def __init__(self, pipe_file, name=None, discovery=None): super(NamedPipeListener, self).__init__(name=name) if DiscUtilities().validate_named_pipe(pipe_file) == False: return None self._pipe_file = pipe_file self.msg_queue = Queue() self.discovery = discovery # backpoint to discovery obj # Unblock previous writers BUFFER_SIZE = 65536 ph = None try: ph = os.open(self._pipe_file, os.O_RDONLY | os.O_NONBLOCK) flags = fcntl.fcntl(ph, fcntl.F_GETFL) flags &= ~os.O_NONBLOCK fcntl.fcntl(ph, fcntl.F_SETFL, flags) while True: buffer = os.read(ph, BUFFER_SIZE) if not buffer: break except OSError as err: import errno if err.errno == errno.EAGAIN or err.errno == errno.EWOULDBLOCK: pass # It is supposed to raise one of these exceptions else: raise err finally: if ph: os.close(ph) log.debug('NamedPipeListener is initialized') print 'NamedPipeListener is initialized' self.flag_alive = True self.start()
def _executable_check(self): if DiscUtilities().validate_named_pipe( self.cmd_messenger_pipe) == False: return None # Will not initialize device simulator if simulator list is empty if len(self.endpoint_list) is 0: log.error( "Device simulator failed because simulator list is empty") return
def _executable_check(self): if DiscUtilities().validate_named_pipe(self.cmd_messenger_pipe) == False: return None # Will not initialize device discovery if DISCOVERY_LISTENER list is empty if len(self.endpoint_list) is 0: log.error("Device discovery failed because listener list is empty") return # later needed when register device if self.pkg_registry is None: log.error("Device discovery failed because no package manager's registry info") return