@@ -546,28 +546,14 @@ def __init__(
546
546
self .retry_timeout = retry_timeout
547
547
self ._received : dict [str , asyncio .Future ] = {}
548
548
self ._received_subscriptions : dict [str , asyncio .Queue ] = {}
549
- self ._sending = asyncio .Queue ()
549
+ self ._sending : Optional [ asyncio .Queue ] = None
550
550
self ._send_recv_task = None
551
551
self ._inflight : dict [str , str ] = {}
552
552
self ._attempts = 0
553
553
self ._lock = asyncio .Lock ()
554
554
self ._exit_task = None
555
555
self ._options = options if options else {}
556
556
self ._log_raw_websockets = _log_raw_websockets
557
-
558
- try :
559
- now = asyncio .get_running_loop ().time ()
560
- except RuntimeError :
561
- warnings .warn (
562
- "You are instantiating the AsyncSubstrateInterface Websocket outside of an event loop. "
563
- "Verify this is intended."
564
- )
565
- # default value for in case there's no running asyncio loop
566
- # this really doesn't matter in most cases, as it's only used for comparison on the first call to
567
- # see how long it's been since the last call
568
- now = 0.0
569
- self .last_received = now
570
- self .last_sent = now
571
557
self ._in_use_ids = set ()
572
558
573
559
@property
@@ -603,10 +589,9 @@ async def _cancel(self):
603
589
)
604
590
605
591
async def connect (self , force = False ):
606
- now = await self .loop_time ()
607
- self .last_received = now
608
- self .last_sent = now
609
592
async with self ._lock :
593
+ if self ._sending is None or self ._sending .empty ():
594
+ self ._sending = asyncio .Queue ()
610
595
if self ._exit_task :
611
596
self ._exit_task .cancel ()
612
597
if self .state not in (State .OPEN , State .CONNECTING ) or force :
@@ -683,7 +668,6 @@ async def _recv(self, recd: bytes) -> None:
683
668
if self ._log_raw_websockets :
684
669
raw_websocket_logger .debug (f"WEBSOCKET_RECEIVE> { recd .decode ()} " )
685
670
response = json .loads (recd )
686
- self .last_received = await self .loop_time ()
687
671
if "id" in response :
688
672
async with self ._lock :
689
673
self ._inflight .pop (response ["id" ])
@@ -707,7 +691,7 @@ async def _start_receiving(self, ws: ClientConnection) -> Exception:
707
691
)
708
692
await self ._recv (recd )
709
693
except Exception as e :
710
- logger .exception ("Start receving exception" , exc_info = e )
694
+ logger .exception ("Start receiving exception" , exc_info = e )
711
695
if isinstance (e , ssl .SSLError ):
712
696
e = ConnectionClosed
713
697
for fut in self ._received .values ():
@@ -728,8 +712,8 @@ async def _start_sending(self, ws) -> Exception:
728
712
if self ._log_raw_websockets :
729
713
raw_websocket_logger .debug (f"WEBSOCKET_SEND> { to_send } " )
730
714
await ws .send (to_send )
731
- self .last_sent = await self .loop_time ()
732
715
except Exception as e :
716
+ logger .exception ("Start sending exception" , exc_info = e )
733
717
if to_send is not None :
734
718
self ._received [to_send ["id" ]].set_exception (e )
735
719
self ._received [to_send ["id" ]].cancel ()
0 commit comments