Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cassova opened this issue Jul 29, 2024 · 1 comment
Open

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

cassova opened this issue Jul 29, 2024 · 1 comment
Assignees
Labels
feature new feature added

Comments

@cassova
Copy link

cassova commented Jul 29, 2024

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

@cassova cassova added the feature new feature added label Jul 29, 2024
@cassova
Copy link
Author

cassova commented Jul 29, 2024

Something I also tried that didn't work: export UVICORN_LOOP=asyncio

I was a bit surprised this didn't work given the documentation. I suspect the reason being this comment:

CLI options and the arguments for uvicorn.run() take precedence over environment variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature added
Projects
None yet
Development

No branches or pull requests

2 participants