Skip to content

Commit 1667a83

Browse files
committed
investigate async issue
1 parent 7d779ad commit 1667a83

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

subvortex/core/core_bittensor/subtensor/subtensor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ async def watchdog():
315315
prefix="ReliableSubtensor",
316316
)
317317

318-
btul.logging.info("🔁 Reinstantiating substrate connection...", prefix="ReliableSubtensor")
319318
await subtensor.substrate._reinstantiate_substrate()
320319

321320
if attempt > 0:

subvortex/core/metagraph/metagraph.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -71,40 +71,40 @@ async def start(self):
7171
try:
7272
while not self.should_exit.is_set():
7373
try:
74-
# # 👇 Concurrently wait for either block or shutdown
75-
# wait_block = asyncio.create_task(self.subtensor.wait_for_block())
76-
# wait_exit = asyncio.create_task(self.should_exit.wait())
77-
78-
# done, pending = await asyncio.wait(
79-
# [wait_block, wait_exit],
80-
# timeout=12,
81-
# return_when=asyncio.FIRST_COMPLETED,
82-
# )
83-
84-
# # Cancel the other task that didn't finish
85-
# for task in pending:
86-
# task.cancel()
87-
88-
# # Exit loop if shutdown was triggered
89-
# if self.should_exit.is_set():
90-
# break
91-
92-
# # If wait_for_block() didn't complete
93-
# if wait_block not in done:
94-
# btul.logging.warning(
95-
# f"⏱️ Timeout after 12s while waiting for block. Retrying...",
96-
# prefix=self.settings.logging_name,
97-
# )
98-
# continue
74+
# 👇 Concurrently wait for either block or shutdown
75+
wait_block = asyncio.create_task(self.subtensor.wait_for_block())
76+
wait_exit = asyncio.create_task(self.should_exit.wait())
77+
78+
done, pending = await asyncio.wait(
79+
[wait_block, wait_exit],
80+
timeout=12,
81+
return_when=asyncio.FIRST_COMPLETED,
82+
)
9983

100-
# if wait_block in done and not wait_block.result():
101-
# btul.logging.warning(
102-
# "⚠️ wait_for_block() returned False, skipping...",
103-
# prefix=self.settings.logging_name,
104-
# )
105-
# continue
106-
if not await scbs.wait_for_block(subtensor=self.subtensor):
84+
# Cancel the other task that didn't finish
85+
for task in pending:
86+
task.cancel()
87+
88+
# Exit loop if shutdown was triggered
89+
if self.should_exit.is_set():
90+
break
91+
92+
# If wait_for_block() didn't complete
93+
if wait_block not in done:
94+
btul.logging.warning(
95+
f"⏱️ Timeout after 12s while waiting for block. Retrying...",
96+
prefix=self.settings.logging_name,
97+
)
98+
continue
99+
100+
if wait_block in done and not wait_block.result():
101+
btul.logging.warning(
102+
"⚠️ wait_for_block() returned False, skipping...",
103+
prefix=self.settings.logging_name,
104+
)
107105
continue
106+
# if not await scbs.wait_for_block(subtensor=self.subtensor):
107+
# continue
108108

109109
block = await self.subtensor.get_current_block()
110110
btul.logging.info(

subvortex/miner/metagraph/src/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ async def start(self):
7373
)
7474

7575
# Initialize the subtensor
76-
self.subtensor = btcas.AsyncSubtensor(config=config, retry_forever=True)
76+
self.subtensor = btcas.AsyncSubtensor(
77+
config=config,
78+
retry_forever=True,
79+
)
7780
await self.subtensor.initialize()
7881
btul.logging.info(str(self.subtensor))
7982

@@ -132,8 +135,10 @@ async def shutdown(self):
132135
# await shutdown_event.wait()
133136

134137
import threading
138+
135139
shutdown_complete = threading.Event()
136140

141+
137142
async def main():
138143
runner = Runner()
139144

@@ -148,6 +153,7 @@ def _signal_handler():
148153
await runner.start()
149154
await shutdown_complete.wait() # <--- don't exit until shutdown is complete
150155

156+
151157
async def _shutdown(runner: Runner):
152158
await runner.shutdown()
153159
shutdown_complete.set()

subvortex/miner/neuron/src/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ async def _initialize(self):
197197
MockSubtensor(self.config.netuid, wallet=self.wallet)
198198
if self.config.miner.mock_subtensor
199199
else btcas.AsyncSubtensor(
200-
config=self.config, network=network, retry_forever=True
200+
config=self.config,
201+
network=network,
202+
retry_forever=True,
201203
)
202204
)
203205
await self.subtensor.initialize()

0 commit comments

Comments
 (0)