Lambda scopes are irritating

This commit is contained in:
jesopo 2019-06-06 21:03:25 +01:00
parent 0f7b040165
commit d9de4fdec2

View file

@ -248,6 +248,11 @@ class Bot(object):
item = self._event_queue.get(block=True, timeout=None) item = self._event_queue.get(block=True, timeout=None)
item() item()
def _post_send_factory(self, server, lines):
return lambda: server._post_send(lines)
def _post_read_factory(self, server, lines):
return lambda: server._post_read(lines)
def _write_loop(self): def _write_loop(self):
while self.running: while self.running:
if not self.servers: if not self.servers:
@ -273,7 +278,8 @@ class Bot(object):
except: except:
self.log.error("Failed to write to %s", [str(server)]) self.log.error("Failed to write to %s", [str(server)])
raise raise
self._event_queue.put(lambda: server._post_send(lines)) self._event_queue.put(self._post_send_factory(server,
lines))
def _read_loop(self): def _read_loop(self):
while self.running: while self.running:
@ -310,7 +316,8 @@ class Bot(object):
server.disconnect() server.disconnect()
continue continue
self._event_queue.put(lambda: server._post_read(lines)) self._event_queue.put(self._post_read_factory(server,
lines))
elif event & select.EPOLLHUP: elif event & select.EPOLLHUP:
self.log.warn("Recieved EPOLLHUP for %s", [str(server)]) self.log.warn("Recieved EPOLLHUP for %s", [str(server)])
server.disconnect() server.disconnect()