File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -330,16 +330,24 @@ def base(self):
330
330
def project (self ):
331
331
return self .credentials .project
332
332
333
+ # Clean up the aiohttp session
334
+ #
335
+ # This can run from the main thread if invoked via the weakref callbcak.
336
+ # This can happen even if the `loop` parameter belongs to another thread
337
+ # (e.g. the fsspec IO worker). The control flow here is intended to attempt
338
+ # in-thread asynchronous cleanup first, then fallback to synchronous
339
+ # cleanup (which can handle cross-thread calls).
333
340
@staticmethod
334
341
def close_session (loop , session ):
335
342
if loop is not None and session is not None :
336
343
if loop .is_running ():
337
344
try :
338
- loop = asyncio .get_event_loop ()
339
- loop .create_task (session .close ())
345
+ current_loop = asyncio .get_running_loop ()
346
+ current_loop .create_task (session .close ())
340
347
return
341
348
except RuntimeError :
342
349
pass
350
+
343
351
try :
344
352
sync (loop , session .close , timeout = 0.1 )
345
353
except fsspec .FSTimeoutError :
You can’t perform that action at this time.
0 commit comments