Skip to content

Pass asyncio event loop config to axon to be used by uvicorn #2188

@cassova

Description

@cassova

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:

  1. hardcode axon.py to use loop="asyncio":
        self.fast_config = uvicorn.Config(
            self.app, host="0.0.0.0", port=self.config.axon.port, log_level=log_level, loop="asyncio"
        )
  1. have the loop passed in when an axon is 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
        )
  1. Find a way to attach uvicorn server 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 in loop of type LoopSetupType instead of the AbstractEventLoop type we'd need.

Additional context

No response

Metadata

Metadata

Labels

featurenew feature added

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions