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

SANIC_NO_UVLOOP=true doesn't seem to work #2223

Closed
delfick opened this issue Aug 21, 2021 · 9 comments · Fixed by #2264
Closed

SANIC_NO_UVLOOP=true doesn't seem to work #2223

delfick opened this issue Aug 21, 2021 · 9 comments · Fixed by #2264

Comments

@delfick
Copy link

delfick commented Aug 21, 2021

Describe the bug
Installing sanic with a SANIC_NO_UVLOOP=true in my environment still results in uvloop being installed

Environment (please complete the following information):

  • OS: macOS Big Sur
  • Version 11.5.2

Additional context
Python 3.9.6

Screen Shot 2021-08-22 at 9 15 49 am

@ahopkins
Copy link
Member

image

If you look at the unit tests, you can see if definitely works. Perhaps you have pip cache?

@delfick
Copy link
Author

delfick commented Aug 22, 2021

--no-cache-dir doesn't make a difference and also given it's decided in sanic's setup.py based on the environment variable, it wouldn't make sense for it to anyway!

After some checking, I think the reason is because the wheel doesn't have a setup.py and so when you install via a wheel it doesn't ever do this check https://github.com/sanic-org/sanic/blob/main/setup.py#L138

@ahopkins
Copy link
Member

One of the things that has been a question for a long time on this project is how to gracefully handle this. Obviously, the best scenario would be if pip supported subtractive install_requires:

$ pip install sanic[no-uvloop]

This (to my knowledge) is still not a supported feature. The problem is that we do want uvloop to be installed by default. That will not change. The only other solution that would work is if you do this:

pip install sanic
pip uninstall uvloop

Not ideal, but in CI it is not terrible.

If you have some other thoughts or suggestions, please let me know.

@delfick
Copy link
Author

delfick commented Aug 30, 2021

can we make it so that sanic chooses to use it at runtime rather than forced on us at import time? i.e. I can set an environment variable or sanic option that makes it not set uvloop? that way uvloop can be in the environment, but sanic can choose to not use it

@delfick
Copy link
Author

delfick commented Aug 30, 2021

i.e. move

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
to when you use the loop or make this not happen depending on an environment variable.

@ahopkins
Copy link
Member

ahopkins commented Aug 30, 2021

can we make it so that sanic chooses to use it at runtime rather than forced on us at import time? i.e. I can set an environment variable or sanic option that makes it not set uvloop? that way uvloop can be in the environment, but sanic can choose to not use it

Yeah, that can probably work fine. I did something similar with uvloop by allowing for an application override (for dumps only, we still need to add it for loads).

Probably app.config.NO_UVLOOP would be the most appropriate/consistent, but open to seeing whatever you come up with in your PR.

@delfick
Copy link
Author

delfick commented Dec 23, 2021

Awesome! Thank you so much :)

@prryplatypus
Copy link
Member

Hope it works! :)

@delfick
Copy link
Author

delfick commented Dec 23, 2021

Thanks ❤️

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

Successfully merging a pull request may close this issue.

3 participants