properly closing event loops in client and server

This commit is contained in:
Mose Müller 2025-05-20 13:59:26 +02:00
parent c5eb5f80b4
commit 7c18d86e9c
2 changed files with 8 additions and 2 deletions

View File

@ -33,7 +33,10 @@ class NotifyDict(TypedDict):
def asyncio_loop_thread(loop: asyncio.AbstractEventLoop) -> None:
asyncio.set_event_loop(loop)
loop.run_forever()
try:
loop.run_forever()
finally:
loop.close()
class Client:

View File

@ -182,7 +182,10 @@ class Server:
This method should be called to start the server after it's been instantiated.
"""
self._loop.run_until_complete(self.serve())
try:
self._loop.run_until_complete(self.serve())
finally:
self._loop.close()
async def serve(self) -> None:
process_id = os.getpid()