Skip to content

gh-128289: Add eager_tasks parameter to asyncio.run() and asyncio.Runner - #128293

Merged
asvetlov merged 6 commits into
python:mainfrom
asvetlov:eager-tasks
Oct 29, 2026
Merged

asvetlov merged 6 commits into
python:mainfrom
asvetlov:eager-tasks

Conversation

@asvetlov

@asvetlov asvetlov commented Dec 27, 2024 •

Copy link
Copy Markdown
Contributor

@asvetlov

Copy link
Copy Markdown
Contributor Author

@gvanrossum does the PR fit your vision?
Does eager_task argument sound good or there is better naming?

@asvetlov

asvetlov commented Dec 27, 2024 •

Copy link
Copy Markdown
Contributor Author

A failed hypothesis test for glob is definitely not related to the PR, it is broken in the main branch already.

@graingert

Copy link
Copy Markdown
Contributor

This will also need some way to set this in IsolatedAsyncioTestCase

@asvetlov

Copy link
Copy Markdown
Contributor Author

This will also need some way to set this in IsolatedAsyncioTestCase

Good idea. A classvar attribute with special name maybe, something like EAGER_TASKS = True.

I would update async test case when this PR will land.

@graingert

graingert commented Dec 27, 2024 •

Copy link
Copy Markdown
Contributor

Possibly we could stick to just using loop_factory for this and asyncio.Task can issue the deprecation warning if eager isn't set to True in the constructor. (We could use eager = True, False or None to decide the warning)

@asvetlov

Copy link
Copy Markdown
Contributor Author

Possibly we could stick to just using loop_factory for this and asyncio.Task can issue the deprecation warning if eager isn't set to True in the constructor. (We could use eager = True, False or None to decide the warning)

Sorry, I don't follow how loop_factory is related to lazy/eager task creation.

Could you please elaborate?

@graingert

graingert commented Dec 27, 2024 •

Copy link
Copy Markdown
Contributor

Currently for 3.13 to enable eager tasks the approach is to do:

def loop_factory():
    loop = asyncio.EventLoop()
    loop.set_task_factory(asyncio.eager_task_factory)
    return loop

asyncio.run(amain(), loop_factory=loop_factory)

So this should still work and not trigger a deprecation warning

@asvetlov

Copy link
Copy Markdown
Contributor Author

I consider loop.set_task_factory() as low-level function.
If a user overrides eager_tasks by set_task_factory() it is totally legal behavior, a user is free to do it on its own.

@graingert

graingert commented Dec 28, 2024 •

Copy link
Copy Markdown
Contributor

We could provide an eager loop factory and deprecate calling asyncio.Task(eager_start=None)

Code would look like asyncio.run(amain(), loop_factory=asyncio.eager_loop_factory)

@asvetlov

Copy link
Copy Markdown
Contributor Author

I've got you finally, I hope.
Yes, it is a viable solution too.
Anyway, we should reach some conclusion in the discuss group first before any of PR will get a chance to be merged.

Comment thread Doc/library/asyncio-runner.rst Resolved
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 20, 2026

@gvanrossum gvanrossum left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@asvetlov -- LGTM except everything needs to be moved over to 3.15 now... And before May 1 to make the beta 1 deadline (feature cut-off).

Comment thread Doc/library/asyncio-runner.rst Resolved
Comment thread Doc/library/asyncio-runner.rst Resolved
Comment thread Doc/library/asyncio-runner.rst Resolved
Comment thread Doc/library/asyncio-runner.rst Resolved
Comment thread Doc/whatsnew/3.14.rst Resolved
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 14, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 16, 2026
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
@asvetlov
asvetlov requested a review from AA-Turner as a code owner October 29, 2026 08:35
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 29, 2026
asvetlov and others added 2 commits October 29, 2026 09:36
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
# Conflicts:
#	Doc/library/asyncio-runner.rst
@asvetlov asvetlov removed type-feature A feature request or enhancement stale Stale PR or inactive for long period of time. labels Oct 29, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35492776 | 📁 Comparing 94bd03c against main (16f209b)

  🔍 Preview build  

3 files changed
± library/asyncio-runner.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@asvetlov
asvetlov merged commit 2b2520a into python:main Oct 29, 2026
102 of 105 checks passed
@asvetlov
asvetlov deleted the eager-tasks branch October 29, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants