@@ -544,9 +544,8 @@ def __init__(
544544 self .last_sent = now
545545
546546 async def __aenter__ (self ):
547- async with self ._lock :
548- self ._in_use += 1
549- await self .connect ()
547+ self ._in_use += 1
548+ await self .connect ()
550549 return self
551550
552551 @staticmethod
@@ -559,18 +558,19 @@ async def connect(self, force=False):
559558 self .last_sent = now
560559 if self ._exit_task :
561560 self ._exit_task .cancel ()
562- if not self ._initialized or force :
563- self ._initialized = True
564- try :
565- self ._receiving_task .cancel ()
566- await self ._receiving_task
567- await self .ws .close ()
568- except (AttributeError , asyncio .CancelledError ):
569- pass
570- self .ws = await asyncio .wait_for (
571- connect (self .ws_url , ** self ._options ), timeout = 10
572- )
573- self ._receiving_task = asyncio .create_task (self ._start_receiving ())
561+ async with self ._lock :
562+ if not self ._initialized or force :
563+ try :
564+ self ._receiving_task .cancel ()
565+ await self ._receiving_task
566+ await self .ws .close ()
567+ except (AttributeError , asyncio .CancelledError ):
568+ pass
569+ self .ws = await asyncio .wait_for (
570+ connect (self .ws_url , ** self ._options ), timeout = 10
571+ )
572+ self ._receiving_task = asyncio .create_task (self ._start_receiving ())
573+ self ._initialized = True
574574
575575 async def __aexit__ (self , exc_type , exc_val , exc_tb ):
576576 async with self ._lock : # TODO is this actually what I want to happen?
0 commit comments