bittensor
bittensor copied to clipboard
Pass asyncio event loop config to `axon` to be used by `uvicorn`
Is your feature request related to a problem? Please describe.
Yes. When the package uvloop is installed with SN1, you get an error There is no current event loop in thread 'Thread-4 (run)'.. This occurs because uvloop overrides the asyncio loop functionality and now requires a loop to be defined within the bittensor package.
Describe the solution you'd like
I suggest passing in a loop: asyncio.LoopSetupType into the axon.__init__(...).
Describe alternatives you've considered
I see a few possible solutions:
- hardcode
axon.pyto useloop="asyncio":
self.fast_config = uvicorn.Config(
self.app, host="0.0.0.0", port=self.config.axon.port, log_level=log_level, loop="asyncio"
)
- have the
looppassed in when anaxonis initiated:
def __init__(
self,
wallet: Optional["bittensor.wallet"] = None,
config: Optional["bittensor.config"] = None,
port: Optional[int] = None,
ip: Optional[str] = None,
external_ip: Optional[str] = None,
external_port: Optional[int] = None,
max_workers: Optional[int] = None,
loop: Optional[asyncio.LoopSetupType] = None, # new parameter
):
...
self.fast_config = uvicorn.Config(
self.app, host="0.0.0.0", port=self.config.axon.port, log_level=log_level, loop=loop
)
- Find a way to attach
uvicornserver to an existing event loop. This doesn't seem to be supported from what I can find. They did make this change awhile back but was later removed for reasons I haven't been able to determine. The server itself now only takes inloopof typeLoopSetupTypeinstead of theAbstractEventLooptype we'd need.
Additional context
No response