wait the shutdown event instead of running forever
This commit is contained in:
parent
1c860e8578
commit
9d772a45d5
1 changed files with 2 additions and 1 deletions
|
@ -111,6 +111,7 @@ class Server:
|
|||
def stop(self):
|
||||
for task in reversed(self.cancellable_tasks):
|
||||
task.cancel()
|
||||
self.shutdown_event.set()
|
||||
|
||||
def run(self):
|
||||
loop = asyncio.get_event_loop()
|
||||
|
@ -118,6 +119,6 @@ class Server:
|
|||
loop.add_signal_handler(signal.SIGINT, self.stop)
|
||||
loop.add_signal_handler(signal.SIGTERM, self.stop)
|
||||
loop.run_until_complete(self.start())
|
||||
loop.run_forever()
|
||||
loop.run_until_complete(self.shutdown_event.wait())
|
||||
finally:
|
||||
loop.run_until_complete(loop.shutdown_asyncgens())
|
||||
|
|
Loading…
Reference in a new issue