GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-128307: support eager_start kwarg in create_eager_task_factory, and pass kwargs from asyncio.create_task and TaskGroup.create_task by graingert · Pull Request #128306 · python/cpython

Conversation

@graingert

@graingert graingert commented Dec 28, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: add eager_start parameter to loop.create_task #128307

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@graingert graingert changed the title add eager_start to create_task gh-128307: add eager_start to create_task Dec 28, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Dec 28, 2024
add eager_start parameter to loop.create_task #128307
Closed
@graingert graingert changed the title gh-128307: add eager_start to create_task gh-128307: add eager_start kwarg to asyncio.create_task Dec 28, 2024
@graingert
graingert force-pushed the add-eager-start-to-create-task branch from c809133 to 2f101b3 Compare December 28, 2024 10:58
graingert
graingert commented Dec 28, 2024
View reviewed changes
Comment thread Lib/asyncio/base_events.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert commented Dec 28, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-12-28-11-01-36.gh-issue-128307.BRCYTA.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@asvetlov

asvetlov commented Dec 28, 2024

Copy link
Copy Markdown
Contributor

TaskGroup.create_task() aslo should accept eager_start argument I guess.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert

graingert commented Dec 28, 2024

Copy link
Copy Markdown
Contributor Author

TaskGroup.create_task() aslo should accept eager_start argument I guess.

yup, it's in I just forgot to add it to the news

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert commented Dec 29, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-12-28-11-01-36.gh-issue-128307.BRCYTA.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert commented Dec 29, 2024
View reviewed changes
Comment thread Lib/asyncio/base_events.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert commented Dec 29, 2024
View reviewed changes
Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert commented Dec 29, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-12-28-11-01-36.gh-issue-128307.BRCYTA.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@graingert
graingert marked this pull request as ready for review December 29, 2024 08:48
@graingert
graingert requested review from 1st1, kumaraditya303 and willingc as code owners December 29, 2024 08:48
@bedevere-app bedevere-app Bot added the awaiting review label Dec 29, 2024
@graingert
graingert marked this pull request as draft January 21, 2025 05:51
@bedevere-app bedevere-app Bot removed the awaiting review label Jan 21, 2025
graingert
graingert commented Jan 21, 2025
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2024-12-28-11-01-36.gh-issue-128307.BRCYTA.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@graingert graingert changed the title gh-128307: add eager_start kwarg to asyncio.create_task gh-128307: add eager_start kwarg to loop.create_task Jan 21, 2025
graingert and others added 3 commits January 21, 2025 09:26
@graingert
support eager_start kwarg in create_eager_task_factory
23d2c42
@blurb-it @graingert
📜🤖 Added by blurb_it.
da5cab3
@graingert
Update Misc/NEWS.d/next/Library/2024-12-28-11-01-36.gh-issue-128307.B…
7bce401
…RCYTA.rst
@graingert
graingert force-pushed the add-eager-start-to-create-task branch from 0699ae2 to 7bce401 Compare January 21, 2025 09:26
@graingert graingert changed the title gh-128307: add eager_start kwarg to loop.create_task gh-128307: support eager_start kwarg in create_eager_task_factory Jan 21, 2025
graingert
graingert commented Jan 21, 2025
View reviewed changes
Comment thread Lib/asyncio/base_events.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@graingert
Update Lib/asyncio/base_events.py
8ad26fc
graingert
graingert commented Jan 21, 2025
View reviewed changes
Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@graingert
Update Lib/asyncio/tasks.py
90f9ef2
@graingert

graingert commented May 4, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

How would the loop even know what type task factory was installed so as to raise?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented May 4, 2025

Copy link
Copy Markdown
Member
  • The segfault is being worked on, so let's assume it will get fixed in time and continue to work on this as if it's fixed. The Tuesday deadline is very close!
  • In response to Tin's nice table, that's exactly what I assume. I am okay with the exception: it represent a reality of the current implementation and I don't want to add work before beta 1. We may be able to fix that in a later feature release.
  • Thomas: "How would the loop even know what type task factory was installed so as to raise?" -- I'm not sure what this refers to. Maybe Tin's remark "there's no way to use the type system to help"? But I still don't understand it. Maybe it's not important, so I'll ignore it for now.

Assuming the segfault will be fixed, let's just work through adding eager_start to all create_task methods. (We can test with the crux of that fix patched in.)

@graingert Do you need help writing any code? One thing I'd like to ensure is that at least eager_start=None (even when explicitly given) is not passed to the task factory, to deal with 3rd party task factories that haven't been updated to support this argument.

It might be possible to come up with a protocol whereby a task factory communicates which eager_start values it supports (e.g. a function attribute on the factory), but that seems a future extension (we'll hopefully learn during beta whether this is needed).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert

graingert commented May 5, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I strongly disagree with raising an exception in the currently supported loop.create_task(eager_start=True) case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mikeshardmind

mikeshardmind commented May 5, 2025

Copy link
Copy Markdown
Contributor

I strongly disagree with raising an exception in the currently supported loop.create_task(eager_start=True) case.

So what would you have happen if the task factory doesn't support eager starts? This API is a breaking change if lazy task factories now must handle this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert

graingert commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

Ah I see, yes then an exception in that case is the current behaviour

mikeshardmind reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum reviewed May 5, 2025
View reviewed changes
Comment thread Lib/test/test_asyncio/test_eager_task_factory.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert and others added 3 commits May 5, 2025 04:35
@graingert
Merge branch 'main' into add-eager-start-to-create-task
8aab5f1
@graingert
Merge branch 'main' into add-eager-start-to-create-task
a410125
@gvanrossum-ms
Change TaskGroup.create_task and tasks.create_task to **kwargs
1a45d43
@python-cla-bot

python-cla-bot Bot commented May 5, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum-ms

gvanrossum-ms commented May 5, 2025

Copy link
Copy Markdown
Contributor

Ah I see, yes then an exception in that case is the current behaviour

But by looking at more of the code I just learned that the eagerness is purely implemented by passing Task(..., eager_start=True) so there is no need to have that exception in the table!

There's one bit of behavior that's changed -- not sure if we care (the docs do not mention it): if you explicitly use create_task(..., context=None) it will pass context=None to the task factory, whereas the original code would not pass it. But is anyone passing context=None explicitly? Ditto for eager_start=None, though we could say that that's the same as False.

Tinche reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum-ms

gvanrossum-ms commented May 5, 2025

Copy link
Copy Markdown
Contributor

I know why the tests fail, will fix in a moment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum-ms
Fix bug I introduced in tasks.create_task()
7654a85
graingert
graingert commented May 5, 2025
View reviewed changes
Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

graingert
graingert commented May 5, 2025
View reviewed changes
Comment thread Lib/asyncio/tasks.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@graingert
Update Lib/asyncio/tasks.py
74b02d4
gvanrossum
gvanrossum approved these changes May 5, 2025
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

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.

@graingert Are you okay if I merge this once the tests pass?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
graingert
graingert commented May 5, 2025
View reviewed changes

@graingert graingert left a comment

Copy link
Copy Markdown
Contributor Author

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.

Just giving everything a final look over

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@graingert graingert changed the title gh-128307: support eager_start kwarg in create_eager_task_factory gh-128307: support eager_start kwarg in create_eager_task_factory, and pass kwargs from asyncio.create_task and TaskGroup.create_task May 5, 2025
@graingert

graingert commented May 5, 2025

Copy link
Copy Markdown
Contributor Author

LGTM! Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum
gvanrossum enabled auto-merge (squash) May 5, 2025 04:45
@gvanrossum
gvanrossum merged commit 08d7687 into python:main May 5, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label May 5, 2025
@gvanrossum

gvanrossum commented May 5, 2025

Copy link
Copy Markdown
Member

W00t! Goodnight everyone. Welcome to beta 1.

hugovk, graingert, and Tinche reacted with hooray emoji dimaqq and graingert reacted with heart emoji
All reactions
  • 🎉 3 reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert
graingert deleted the add-eager-start-to-create-task branch May 5, 2025 04:59
@bedevere-bot

bedevere-bot commented May 5, 2025

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Debian root 3.x (tier-1) has failed when building commit 08d7687.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/345/builds/11228) and take a look at the build logs.
  4. Check if the failure is related to this commit (08d7687) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/345/builds/11228

Failed tests:

  • test_decimal
  • test_external_inspection

Failed subtests:

  • test_async_remote_stack_trace - test.test_external_inspection.TestGetStackTrace.test_async_remote_stack_trace

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/test_external_inspection.py", line 269, in test_async_remote_stack_trace
    self.assertEqual(stack_trace, expected_stack_trace)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Lists differ: [[('c[62 chars]y', 10), ('c4', '/tmp/test_python_sp6aoafc/tmp[1293 chars]]]]]] != [[('c[62 chars]y', 11), ('c4', '/tmp/test_python_sp6aoafc/tmp[1308 chars]]]]]]


Traceback (most recent call last):
  File "/root/buildarea/3.x.angelico-debian-amd64/build/Lib/test/test_external_inspection.py", line 269, in test_async_remote_stack_trace
    self.assertEqual(stack_trace, expected_stack_trace)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Lists differ: [[('c[62 chars]y', 10), ('c4', '/tmp/test_python_9w2frcjy/tmp[1293 chars]]]]]] != [[('c[62 chars]y', 11), ('c4', '/tmp/test_python_9w2frcjy/tmp[1308 chars]]]]]]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dimaqq

dimaqq commented May 6, 2025

Copy link
Copy Markdown
Contributor

The test_external_inspection failure seems relevant, as some of the sample code covered by test is async code.
Perhaps the test itself needs to be updated?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@graingert

graingert commented May 6, 2025

Copy link
Copy Markdown
Contributor Author

It's already fixed, here's the issue: #133419

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dimaqq
dimaqq reviewed May 6, 2025
View reviewed changes
Comment thread Lib/asyncio/tasks.py


def create_task(coro, *, name=None, context=None):
def create_task(coro, **kwargs):

@dimaqq dimaqq May 6, 2025

Copy link
Copy Markdown
Contributor

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.

From the Python user perspective, I don't like this change.
It obscures the allowed kwargs and makes it harder for IDEs to provide suggestions.

I suppose we'd be relying on https://github.com/python/typeshed/blob/main/stdlib/asyncio/tasks.pyi from now on?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gvanrossum gvanrossum May 6, 2025

Copy link
Copy Markdown
Member

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.

I agree it would be nice if we could avoid the **kwargs, but it make the implementation more complex at every level of indirection (asyncio.create_task -> loop.create_task -> Task, and also TaskGroup.create_task -> loop.create_task -> Task).

IDEs should be using typeshed anyway. (And we should update tasks.pyi to have a case for 3.14 that adds eager_start and **kwargs. In fact this should be done to all the create_task definitions found in typeshed's asyncio definitions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@graingert @gvanrossum @Pranjal095
pythongh-128307: Support eager_start=<bool> in create_eager_task_fact…
17986c3
…ory and various create_task functions (python#128306)

Some create_task() functions were changed from `name=None, context=None` to `**kwargs`.

Co-authored-by: Guido van Rossum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gvanrossum gvanrossum gvanrossum approved these changes
@gpshead gpshead gpshead approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
+2 more reviewers
@dimaqq dimaqq dimaqq left review comments
@gvanrossum-ms gvanrossum-ms gvanrossum-ms left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@graingert @asvetlov @hugovk @gpshead @Tinche @gvanrossum @mikeshardmind @gvanrossum-ms @bedevere-bot @dimaqq
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.