File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
async_substrate_interface Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 9
9
import logging
10
10
import ssl
11
11
import time
12
+ import warnings
12
13
from hashlib import blake2b
13
14
from typing import (
14
15
Optional ,
@@ -530,23 +531,31 @@ def __init__(
530
531
self ._exit_task = None
531
532
self ._open_subscriptions = 0
532
533
self ._options = options if options else {}
533
- self .last_received = time .time ()
534
- self .last_sent = time .time ()
534
+ try :
535
+ now = asyncio .get_running_loop ().time ()
536
+ except RuntimeError :
537
+ warnings .warn (
538
+ "You are instantiating the AsyncSubstrateInterface Websocket outside of an event loop. "
539
+ "Verify this is intended."
540
+ )
541
+ now = asyncio .new_event_loop ().time ()
542
+ self .last_received = now
543
+ self .last_sent = now
535
544
536
545
async def __aenter__ (self ):
537
546
async with self ._lock :
538
547
self ._in_use += 1
539
548
await self .connect ()
540
- now = asyncio .get_running_loop ().time ()
541
- self .last_received = now
542
- self .last_sent = now
543
549
return self
544
550
545
551
@staticmethod
546
552
async def loop_time () -> float :
547
553
return asyncio .get_running_loop ().time ()
548
554
549
555
async def connect (self , force = False ):
556
+ now = await self .loop_time ()
557
+ self .last_received = now
558
+ self .last_sent = now
550
559
if self ._exit_task :
551
560
self ._exit_task .cancel ()
552
561
if not self ._initialized or force :
You can’t perform that action at this time.
0 commit comments