fix: replace deprecated asyncio.get_event_loop() and deduplicate network init#395
Open
t7929375-eng wants to merge 1 commit intoentrius:testfrom
Open
Conversation
…ork init in CLI commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both
miner_postandminer_checkCLI commands useasyncio.get_event_loop().run_until_complete()which is deprecated since Python 3.10 (emitsDeprecationWarning) and raisesRuntimeErrorin Python 3.12+ when no running event loop exists.Additionally, both commands duplicate the bittensor initialization block (wallet, subtensor, metagraph, dendrite) — once inside
console.status()and once outside for JSON mode — making the code fragile and harder to maintain.Solution
asyncio.get_event_loop().run_until_complete(coro)withasyncio.run(async_fn())— the modern equivalent that properly creates and manages the event loop._connect()helper to eliminate the duplicated 4-line init block in each command._broadcast()/_check()async helpers to avoid repeating the dendrite call.Changes
post.py_connect()for wallet/subtensor/metagraph/dendrite init (−8 duplicated lines)_broadcast()coroutine, replace 2×asyncio.get_event_loop().run_until_complete()check.py_connect()extraction (−8 duplicated lines)_check()coroutine, replace 2×asyncio.get_event_loop().run_until_complete()Net result: +38 / −48 lines (code reduction).
Type of Change
Testing
ruff checkpassesruff formatpassespyrightpasses (0 errors)Checklist
cc @anderdc @LandynDev