Exemple #1
0
 def destruct(self):
     if self._shm_key:
         print "[%s] catch term sinal, ready to save to shm..." % self.__class__.__name__
         new_shm_str = json.dumps(self._date_map)
         ret = shm_open(self._shm_key, self._shm_size)
         ret = shm_write(new_shm_str)
         if ret == -2:
             print "[%s] new shm str's size[%s] is too large!" % (self.__class__.__name__, len(new_shm_str))
         elif ret == -1:
             print "[%s] get shared memory failed!" % self.__class__.__name__
         else:
             print "[%s] save succ!" % self.__class__.__name__
Exemple #2
0
 def mount_shm(self, shm_key, shm_size=102400):
     ret = shm_open(shm_key, shm_size)
     self._date_map = {}
     if ret == -1:
         print "[%s] get shared memory failed!" % self.__class__.__name__
         sys.exit(0)
     else:
         self._shm_key = shm_key
         self._shm_size = shm_size
         print "[%s] get shared memory succ!" % self.__class__.__name__
         shm_str = shm_read()
         print "%s read shm:%s" % (self.__class__.__name__, shm_str)
         if not shm_str:
             self._date_map = {}
         else:
             self._date_map = json.loads(shm_str)
Exemple #3
0
 def clear_shm(self):
     if self._shm_key:
         # clear the shm map
         ret = shm_open(self._shm_key, self._shm_size)
         shm_write('')