Stop passing loop to asyncio.gather

This commit is contained in:
Tulir Asokan 2020-07-11 16:22:38 +03:00
parent 09108f6a73
commit 03a1fdaaf5
2 changed files with 4 additions and 6 deletions

View File

@ -73,13 +73,12 @@ try:
log.info("Starting server") log.info("Starting server")
loop.run_until_complete(server.start()) loop.run_until_complete(server.start())
log.info("Starting clients and plugins") log.info("Starting clients and plugins")
loop.run_until_complete(asyncio.gather(*[client.start() for client in clients], loop=loop)) loop.run_until_complete(asyncio.gather(*[client.start() for client in clients]))
log.info("Startup actions complete, running forever") log.info("Startup actions complete, running forever")
loop.run_forever() loop.run_forever()
except KeyboardInterrupt: except KeyboardInterrupt:
log.info("Interrupt received, stopping clients") log.info("Interrupt received, stopping clients")
loop.run_until_complete(asyncio.gather(*[client.stop() for client in Client.cache.values()], loop.run_until_complete(asyncio.gather(*[client.stop() for client in Client.cache.values()]))
loop=loop))
if stop_log_listener is not None: if stop_log_listener is not None:
log.debug("Closing websockets") log.debug("Closing websockets")
loop.run_until_complete(stop_log_listener()) loop.run_until_complete(stop_log_listener())

View File

@ -137,11 +137,10 @@ class Client:
await self.start_plugins() await self.start_plugins()
async def start_plugins(self) -> None: async def start_plugins(self) -> None:
await asyncio.gather(*[plugin.start() for plugin in self.references], loop=self.loop) await asyncio.gather(*[plugin.start() for plugin in self.references])
async def stop_plugins(self) -> None: async def stop_plugins(self) -> None:
await asyncio.gather(*[plugin.stop() for plugin in self.references if plugin.started], await asyncio.gather(*[plugin.stop() for plugin in self.references if plugin.started])
loop=self.loop)
def start_sync(self) -> None: def start_sync(self) -> None:
if self.sync: if self.sync: