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

use asyncio.run(..., loop_factory) to avoid asyncio.set_event_loop_policy #2130

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

graingert
Copy link
Member

@graingert graingert commented Oct 14, 2023

Summary

set_event_loop_policy will be deprecated in python 3.13 and uvloop.EventLoopPolicy is deprecated already, this backports and uses the preferred loop_factory keyword to configure asyncio.run

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@graingert graingert marked this pull request as draft October 14, 2023 11:04
@graingert graingert marked this pull request as ready for review October 15, 2023 19:36

import uvloop


def uvloop_setup(use_subprocess: bool = False) -> None:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uvloop.EventLoopPolicy is deprecated


logger = logging.getLogger("uvicorn.error")


def asyncio_setup(use_subprocess: bool = False) -> None:
if sys.platform == "win32" and use_subprocess:
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_event_loop_policy will be deprecated in python 3.13

@graingert
Copy link
Member Author

This still needs a doc change

@graingert
Copy link
Member Author

actually this doesn't need a doc change as --loop never allowed a custom loop setup function

@Kludex Kludex force-pushed the avoid-set-event-loop-policy branch from f6f7a27 to 6450a87 Compare April 14, 2024 20:34
@Kludex Kludex force-pushed the avoid-set-event-loop-policy branch from 6450a87 to 849169f Compare August 18, 2024 11:56
@gnir-work gnir-work mentioned this pull request Aug 18, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants