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 99import logging
1010import ssl
1111import time
12+ import warnings
1213from hashlib import blake2b
1314from typing import (
1415 Optional ,
@@ -530,23 +531,31 @@ def __init__(
530531 self ._exit_task = None
531532 self ._open_subscriptions = 0
532533 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
535544
536545 async def __aenter__ (self ):
537546 async with self ._lock :
538547 self ._in_use += 1
539548 await self .connect ()
540- now = asyncio .get_running_loop ().time ()
541- self .last_received = now
542- self .last_sent = now
543549 return self
544550
545551 @staticmethod
546552 async def loop_time () -> float :
547553 return asyncio .get_running_loop ().time ()
548554
549555 async def connect (self , force = False ):
556+ now = await self .loop_time ()
557+ self .last_received = now
558+ self .last_sent = now
550559 if self ._exit_task :
551560 self ._exit_task .cancel ()
552561 if not self ._initialized or force :
You can’t perform that action at this time.
0 commit comments