diff --git a/findmy/util/closable.py b/findmy/util/closable.py index 406a037..fbac882 100644 --- a/findmy/util/closable.py +++ b/findmy/util/closable.py @@ -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