Skip to content

Commit a99bdf1

Browse files
Fix failing async storage test
1 parent 0cf44aa commit a99bdf1

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

  • tilebox-storage/tilebox/storage

tilebox-storage/tilebox/storage/aio.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import contextlib
23
import hashlib
34
import os
45
import shutil
@@ -56,8 +57,21 @@ def __init__(self, auth: dict[str, tuple[str, str]]) -> None:
5657
self._auth = auth
5758

5859
def __del__(self) -> None:
59-
for client in self._clients.values():
60-
asyncio.run(client.close())
60+
if not self._clients:
61+
return
62+
63+
with contextlib.suppress(Exception):
64+
asyncio.get_running_loop().create_task(self.close())
65+
return
66+
67+
with contextlib.suppress(Exception):
68+
asyncio.run(self.close())
69+
70+
async def close(self) -> None:
71+
clients = list(self._clients.values())
72+
self._clients.clear()
73+
for client in clients:
74+
await client.close()
6175

6276
async def download_quicklook(
6377
self, datapoint: xr.Dataset | ASFStorageGranule, output_dir: Path | None = None

0 commit comments

Comments
 (0)