File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -314,17 +314,20 @@ def close(self):
314314 if self ._exchange_ws :
315315 self ._exchange_ws .cleanup ()
316316 logger .debug ("Exchange object destroyed, closing async loop" )
317+ loop_running = self .loop .is_running () or asyncio .get_event_loop ().is_running ()
317318 if (
318319 getattr (self , "_api_async" , None )
319320 and inspect .iscoroutinefunction (self ._api_async .close )
320321 and self ._api_async .session
322+ and not loop_running
321323 ):
322324 logger .debug ("Closing async ccxt session." )
323325 self .loop .run_until_complete (self ._api_async .close ())
324326 if (
325327 self ._ws_async
326328 and inspect .iscoroutinefunction (self ._ws_async .close )
327329 and self ._ws_async .session
330+ and not loop_running
328331 ):
329332 logger .debug ("Closing ws ccxt session." )
330333 self .loop .run_until_complete (self ._ws_async .close ())
You can’t perform that action at this time.
0 commit comments