diff --git a/Drone/client.py b/Drone/client.py index f004e2d..d3762e8 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -198,7 +198,7 @@ class Client(object): # self._last_ping_time = time.time() # logging.debug("tick") - for key, mask in events: # TODO add notifier to client! + for key, mask in events: connection = key.data if connection is None: pass @@ -217,14 +217,16 @@ class Client(object): if error.errno == errno.EINTR: raise KeyboardInterrupt try: - mapping = self.selector.get_map().values() - notifier_key = self.selector.get_key(messaging.NotifierSock().get_sock()) - notify_only= len(mapping) == 1 and notifier_key in mapping - if notify_only or not mapping: + mapping_fds = self.selector.get_map().keys() # file descriptors + notifier_fd = messaging.NotifierSock().get_sock().fileno() + except (KeyError, RuntimeError) as e: + logger.error("Exception {} occurred when getting connections map!".format(e)) + logger.error("Connections changed during getting connections map, passing") + else: + notify_only= len(mapping_fds) == 1 and notifier_fd in mapping_fds + if notify_only or not mapping_fds: logger.warning("No active connections left!") return - except (RuntimeError, KeyError) as e: - logger.error("Exception {} occured when getting net map!".format(e)) @messaging.message_callback("config_write") @@ -250,5 +252,6 @@ def _response_time(*args, **kwargs): if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) client = Client() client.start()