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
Optional uvloop use #2264
Optional uvloop use #2264
Conversation
I've made it |
That's a breaking change. Not ideal but I think keeping it negative might be the way to go. |
So we're not willing to do this? 🙈 import os
USE_UVLOOP = os.getenv('USE_UVLOOP', True)
no_uvloop = os.getenv('NO_UVLOOP', None)
if no_uvloop is not None:
# Raise DeprecationWarning
USE_UVLOOP = no_uvloop |
Why do they need to be connected? The I think we can just go forward with |
Alright, that sounds good to me! |
EDIT: Just realised that this method will not work for those who update their config after initialising the app. I'll have to give this another try soon. |
@ahopkins, could you confirm if I would have to call the |
It should work as it currently is for most usecases, but I'm unsure about what would happen if there was several Sanic apps running some with the EDIT: After some discussion on Discord we figured it'd be best to default all to use uvloop unless ALL of them are |
…nic into feat/optional-uvloop-use
Things worth noting:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great 🎉
Nice work on this PR 💪
Hmm... Yes, but if one is set to
Docs. |
Correct! Or if one is _default and the other one if False and the _default one is started first (as it will then override the event loop config).
We already do this inside the
💯 |
…ptional-uvloop-use
This is as far as I can get. I've tried adding the following test for the asgi warning, and it works when running it individually, but not when running it with all the other tests in def test_non_default_uvloop_config_raises_warning(app):
app.config.USE_UVLOOP = True
class CustomServer(uvicorn.Server):
def install_signal_handlers(self):
pass
config = uvicorn.Config(app=app, loop="asyncio", limit_max_requests=0)
server = CustomServer(config=config)
with pytest.warns(UserWarning) as records:
server.run()
all_tasks = asyncio.all_tasks(asyncio.get_event_loop())
for task in all_tasks:
task.cancel()
msg = ""
for record in records:
_msg = str(record.message)
if _msg.startswith("You have set the USE_UVLOOP configuration"):
msg = _msg
break
assert msg == (
"You have set the USE_UVLOOP configuration option, but Sanic "
"cannot control the event loop when running in ASGI mode."
"This option will be ignored."
) |
Co-authored-by: Adam Hopkins <adam@amhopkins.com> Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
Resolves #2223.