Title: Deprecate asyncio policy system · Issue #127949 · python/cpython · GitHub
Open Graph Title: Deprecate asyncio policy system · Issue #127949 · python/cpython
X Title: Deprecate asyncio policy system · Issue #127949 · python/cpython
Description: asyncio's policy system deprecation asyncio's policy system1 has been a source of confusion and problems in asyncio for a very long time. The policies no longer serve a real purpose. Loops are always per thread, there is no need to have ...
Open Graph Description: asyncio's policy system deprecation asyncio's policy system1 has been a source of confusion and problems in asyncio for a very long time. The policies no longer serve a real purpose. Loops are alwa...
X Description: asyncio's policy system deprecation asyncio's policy system1 has been a source of confusion and problems in asyncio for a very long time. The policies no longer serve a real purpose. Loops ...
Opengraph URL: https://github.com/python/cpython/issues/127949
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Deprecate asyncio policy system","articleBody":"#### asyncio's policy system deprecation\r\n\r\nasyncio's policy system[^1] has been a source of confusion and problems in asyncio for a very long time. The policies no longer serve a real purpose. Loops are always per thread, there is no need to have a \"current loop\" when no loop is currently running. This issue discusses the changes to deprecate it in Python 3.14 and schedule its removal in 3.16 or later.\r\n\r\nThe usual user applications would use the runner APIs (see flowchart) while those who want more control like Jupyter project can create an event loop and manage it themselves, the difference would be that instead of them first getting the policy then event loop then can directly create it like\r\n\r\n```py\r\nloop = MyCustomEventLoop()\r\nloop.run_until_complete(task)\r\n```\r\nrather than currently\r\n```py\r\nasyncio.set_event_loop_policy(MyPolicy())\r\npolicy = asyncio.get_event_loop_policy()\r\nloop = policy.new_event_loop()\r\nloop.run_until_complete(task)\r\n```\r\n\r\nSee these discussions for more background:\r\n\r\n- https://github.com/python/cpython/issues/83710#issuecomment-1093855411\r\n- https://github.com/python/cpython/issues/93453#issue-1259542498\r\n- https://github.com/python/cpython/issues/94597#issuecomment-1270840197\r\n- https://github.com/python/cpython/issues/94597\r\n\r\n##### Functions and classes to be deprecated and later removed\r\n- [x] `asyncio.get_event_loop_policy`\r\n- [x] `asyncio.set_event_loop_policy`\r\n- [x] `asyncio.AbstractEventLoopPolicy`\r\n- [x] `asyncio.DefaultEventLoopPolicy`\r\n- [x] `asyncio.WindowsSelectorEventLoopPolicy`\r\n- [x] `asyncio.WindowsProactorEventLoopPolicy`\r\n- [x] `asyncio.set_event_loop`\r\n\r\n##### Functions to be modified\r\n- `asyncio.get_event_loop` - In 3.16 or later this will become an alias to `get_running_loop`.\r\n- `asyncio.new_event_loop` - In 3.16 or later this will ignore custom policies and will be an alias to `asyncio.EventLoop`\r\n- `asyncio.run` \u0026 `asyncio.Runner` - In 3.16 or later this will be modified to not use policy system as that will be gone and rely solely on *loop_factory*.\r\n\r\n#### The Grand Plan\r\n\r\n- To minimize changes, all the deprecated functions will be underscored i.e. `set_event_loop` -\u003e `_set_event_loop` and `set_event_loop` will emit the warning then call `_set_event_loop` as its underlying implementation. This way internally asyncio can still call these functions until they are removed without need of many ignore warnings and the tests too can easily be adapted.\r\n- The deprecated classes will emit warnings when they are subclassed as it was done for child watchers.\r\n- The runner APIs will be remain unmodified but making sure that correct warnings are emitted internally when policy system is used.\r\n\r\n#### The Future\r\n\r\n\r\n```mermaid\r\n---\r\ntitle: Flowchart for asyncio.run\r\n---\r\nflowchart TD\r\n A[\"asyncio.run(coro, loop_factory=...)\"] --\u003e B{loop_factory}\r\n B --\u003e|loop_factory is None| D{platform}\r\n B --\u003e|loop_factory is not None| E[\"loop = loop_factory()\"]\r\n D --\u003e |Unix| F[\"loop = SelectorEventLoop()\"]\r\n D --\u003e |Windows| G[\"loop = ProactorEventLoop()\"]\r\n E --\u003e H\r\n F --\u003e H\r\n G --\u003e H \r\n H[\"loop.run_until_complete(coro)\"]\r\n```\r\n\r\n\r\n[^1]: https://docs.python.org/3.14/library/asyncio-policy.html\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-128024\r\n* gh-128053\r\n* gh-128172\r\n* gh-128215\r\n* gh-128216\r\n* gh-128218\n* gh-128269\n* gh-128290\n* gh-131805\n* gh-131806\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/kumaraditya303","@type":"Person","name":"kumaraditya303"},"datePublished":"2024-12-14T16:37:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":15},"url":"https://github.com/127949/cpython/issues/127949"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9aeaf40d-6645-52c9-9168-abe1c3f763ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F22:2786B7:AD2310:EB6B8D:6969E58D |
| html-safe-nonce | 1405cd4e896c5098427f4acd739f4228544776f1d894c15a0f5bee8ef27218b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjIyOjI3ODZCNzpBRDIzMTA6RUI2QjhEOjY5NjlFNThEIiwidmlzaXRvcl9pZCI6IjQyMDUwMTc5MjY1Mzc0Mzg2MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b6b6658d29e8873be7dfe90fd3916d1c76cd88db0f19d53c6eefcd6800997bc2 |
| hovercard-subject-tag | issue:2739981235 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/127949/issue_layout |
| twitter:image | https://opengraph.githubassets.com/61208b4cf17d3e4e1c4e00494e79dfd15e39d7d394af587295ddc4fbd13c9865/python/cpython/issues/127949 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/61208b4cf17d3e4e1c4e00494e79dfd15e39d7d394af587295ddc4fbd13c9865/python/cpython/issues/127949 |
| og:image:alt | asyncio's policy system deprecation asyncio's policy system1 has been a source of confusion and problems in asyncio for a very long time. The policies no longer serve a real purpose. Loops are alwa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kumaraditya303 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width