@@ -218,7 +218,8 @@ def status(self):
218218 if connection .is_debug_log_connection :
219219 stopped = connection ._debug_log_task .cancelled ()
220220 else :
221- stopped = connection ._receiver_task .cancelled ()
221+ stopped = connection ._receiver_task is not None and \
222+ connection ._receiver_task .cancelled ()
222223
223224 if stopped or not connection ._ws .open :
224225 return self .ERROR
@@ -451,17 +452,17 @@ async def close(self, to_reconnect=False):
451452 if self ._ws and not self ._ws .closed :
452453 await self ._ws .close ()
453454
454- try :
455- log .debug ('Gathering all tasks for connection close' )
455+ if not to_reconnect :
456+ try :
457+ log .debug ('Gathering all tasks for connection close' )
456458
457- # Avoid gathering the current task
458- tasks_need_to_be_gathered = [task for task in jasyncio .all_tasks ()
459- if task != jasyncio .current_task ()]
460- await jasyncio .gather (* tasks_need_to_be_gathered )
461- except jasyncio .CancelledError :
462- pass
463- except websockets .exceptions .ConnectionClosed :
464- pass
459+ # Avoid gathering the current task
460+ tasks_need_to_be_gathered = [task for task in jasyncio .all_tasks () if task != jasyncio .current_task ()]
461+ await jasyncio .gather (* tasks_need_to_be_gathered )
462+ except jasyncio .CancelledError :
463+ pass
464+ except websockets .exceptions .ConnectionClosed :
465+ pass
465466
466467 self ._pinger_task = None
467468 self ._receiver_task = None
0 commit comments