Skip to content

Commit

Permalink
Merge pull request #60 from malmeloo/fix/coro-never-awaited
Browse files Browse the repository at this point in the history
fix: Unawaited coroutine errors on `Closable`
  • Loading branch information
malmeloo authored Aug 4, 2024
2 parents 04e83e0 + b7ba97f commit 7b8707b
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 7b8707b

Please sign in to comment.