diff --git a/irclog.py b/irclog.py index 09716bb..92b11d2 100644 --- a/irclog.py +++ b/irclog.py @@ -336,7 +336,7 @@ class IRCClientProtocol(asyncio.Protocol): now = time.time() if self.lastSentTime is not None and now - self.lastSentTime < 1: self.logger.debug(f'Rate limited') - await asyncio.wait((asyncio.sleep(self.lastSentTime + 1 - now), self.connectionClosedEvent.wait()), return_when = asyncio.FIRST_COMPLETED) + await asyncio.wait({self.connectionClosedEvent.wait()}, timeout = self.lastSentTime + 1 - now) if self.connectionClosedEvent.is_set(): break self.logger.debug(f'Send: {data!r}') @@ -553,7 +553,7 @@ class IRCClientProtocol(asyncio.Protocol): # The server acknowledges a QUIT by sending an ERROR and closing the connection. The latter triggers connection_lost, so just wait for the closure event. self.logger.info('Quitting') self.send(b'QUIT :Bye') - await asyncio.wait((asyncio.sleep(10), self.connectionClosedEvent.wait()), return_when = asyncio.FIRST_COMPLETED) + await asyncio.wait({self.connectionClosedEvent.wait()}, timeout = 10) if not self.connectionClosedEvent.is_set(): self.logger.error('Quitting cleanly did not work, closing connection forcefully') # Event will be set implicitly in connection_lost. @@ -618,7 +618,7 @@ class IRCClient: await self._protocol.quit() except (ConnectionRefusedError, ssl.SSLError, asyncio.TimeoutError) as e: self.logger.error(str(e)) - await asyncio.wait((asyncio.sleep(5), sigintEvent.wait()), return_when = asyncio.FIRST_COMPLETED) + await asyncio.wait({sigintEvent.wait()}, timeout = 5) if sigintEvent.is_set(): self.logger.debug('Got SIGINT, putting EOF and breaking') self.messageQueue.put_nowait(messageEOF) @@ -707,7 +707,7 @@ class Storage: async def flush_files(self, flushExitEvent): while True: - await asyncio.wait((flushExitEvent.wait(), asyncio.sleep(60)), return_when = asyncio.FIRST_COMPLETED) + await asyncio.wait({flushExitEvent.wait()}, timeout = 60) self.logger.debug('Flushing files') for _, f in self.files.values(): f.flush()