Ejemplo n.º 1
0
    def work(self):

        # update f_map and readers
        f_map = self.get_handle_map()
        readers = self.get_sockets(f_map)

        try:
            ready_to_read, ready_to_write, in_error = select.select(
                readers, [], [], 3)
        except socket.timeout:
            return
        except:
            logger.error('work error')
            return

        for r in ready_to_read:
            for s in f_map:
                if isinstance(s[0], socket.socket):
                    if r == s[0]:
                        s[1](r)
                        break
                elif isinstance(s[0], list):
                    if r in s[0]:
                        s[1](r)
                        break
Ejemplo n.º 2
0
    def run(self):

        self.sub_init()
        self.stop_flag = False

        # open listener
        self.open_listener()

        while not self.stop_flag:
            try:
                self.work()
            except :
                logger.error(sys.exc_info()[0])
                break
Ejemplo n.º 3
0
    def run(self):

        self.sub_init()
        self.stop_flag = False

        # open listener
        self.open_listener()

        while not self.stop_flag:
            try:
                self.work()
            except:
                logger.error(sys.exc_info()[0])
                break
Ejemplo n.º 4
0
    def _daemon_thread(self):
        while True:
            #if not self.send_thread.isAlive() and self.recv_done:#not self.recv_thread.isAlive():
            if (self.send_done and self.recv_done) or ((not self.send_thread.isAlive()) and (not
                    self.recv_thread.isAlive())):#not self.recv_thread.isAlive():
                if self.stop_flag:
                    logger.error('Error happended or stop by user')
                break

            time.sleep(5)

        # Work is done, this instance of DTNConnection could be removed
        self.stop_flag = True
        self.send_thread.join()
        self.recv_thread.join()
        self.clean()
        logger.debug('clean done')
        logger.info('job done')
Ejemplo n.º 5
0
    def _daemon_thread(self):
        while True:
            #if not self.send_thread.isAlive() and self.recv_done:#not self.recv_thread.isAlive():
            if (self.send_done and self.recv_done) or (
                (not self.send_thread.isAlive()) and
                (not self.recv_thread.isAlive())
            ):  #not self.recv_thread.isAlive():
                if self.stop_flag:
                    logger.error('Error happended or stop by user')
                break

            time.sleep(5)

        # Work is done, this instance of DTNConnection could be removed
        self.stop_flag = True
        self.send_thread.join()
        self.recv_thread.join()
        self.clean()
        logger.debug('clean done')
        logger.info('job done')
Ejemplo n.º 6
0
    def work(self):

        # update f_map and readers
        f_map = self.get_handle_map()
        readers = self.get_sockets(f_map)

        try:
            ready_to_read, ready_to_write, in_error = select.select(readers, [], [], 3)
        except socket.timeout:
            return
        except:
            logger.error('work error')
            return

        for r in ready_to_read:
            for s in f_map:
                if isinstance(s[0], socket.socket):
                    if r == s[0]:
                        s[1](r)
                        break
                elif isinstance(s[0], list):
                    if r in s[0]:
                        s[1](r)
                        break