Client mapping fix (#58)

* Fix of idle error in clients

* Working fix of mapping get
This commit is contained in:
artem30801
2019-12-26 18:58:04 +03:00
committed by Arthur Golubtsov
parent 853cc0d3fa
commit 5435a014f2

View File

@@ -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()