use _event_queue for _check, don't .disconnect() from outside of respective

loops
This commit is contained in:
jesopo 2019-06-06 22:36:56 +01:00
parent ae6c65d743
commit ef0c2c65e0

View file

@ -190,15 +190,8 @@ class Bot(object):
return min([timeout for timeout in timeouts if not timeout == None]) return min([timeout for timeout in timeouts if not timeout == None])
def disconnect(self, server: IRCServer.Server): def disconnect(self, server: IRCServer.Server):
try:
self._read_poll.unregister(server.fileno())
except FileNotFoundError:
pass
try:
self._write_poll.unregister(server.fileno())
except FileNotFoundError:
pass
del self.servers[server.fileno()] del self.servers[server.fileno()]
self._trigger_both()
def _timed_reconnect(self, event: EventManager.Event): def _timed_reconnect(self, event: EventManager.Event):
if not self.reconnect(event["server_id"], if not self.reconnect(event["server_id"],
@ -270,12 +263,14 @@ class Bot(object):
self._wtriggered = False self._wtriggered = False
elif event & select.EPOLLOUT: elif event & select.EPOLLOUT:
self._write_poll.unregister(fd) self._write_poll.unregister(fd)
if fd in self.servers:
server = self.servers[fd] server = self.servers[fd]
try: try:
lines = server._send() lines = server._send()
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(self._post_send_factory(server, self._event_queue.put(self._post_send_factory(server,
lines)) lines))
@ -287,7 +282,6 @@ class Bot(object):
self._event_queue.put(lambda: None) self._event_queue.put(lambda: None)
break break
#self.trigger(self._check)
self._event_queue.put(self._check) self._event_queue.put(self._check)
events = self._read_poll.poll(self.get_poll_timeout()) events = self._read_poll.poll(self.get_poll_timeout())
@ -299,6 +293,10 @@ class Bot(object):
with self._rtrigger_lock: with self._rtrigger_lock:
self._rtriggered = False self._rtriggered = False
else: else:
if not fd in self.servers:
self._read_poll.unregister(fd)
continue
server = self.servers[fd] server = self.servers[fd]
if event & select.EPOLLIN: if event & select.EPOLLIN:
lines = server.read() lines = server.read()