Skip to content

Commit

Permalink
fix: Create new event loop for cleanup if current one is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
malmeloo committed Aug 2, 2024
1 parent d92085d commit 870dca7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion findmy/util/closable.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __del__(self) -> None:
"""Attempt to automatically clean up when garbage collected."""
try:
loop = self._loop or asyncio.get_running_loop()
loop.call_soon_threadsafe(loop.create_task, self.close())
if loop.is_running:
loop.call_soon_threadsafe(loop.create_task, self.close())
else:
loop.run_until_complete(self.close())
except RuntimeError:
pass

0 comments on commit 870dca7

Please sign in to comment.