Skip to content

Give the worker a current_task before wait_for and TaskGroup - #375

Closed
gyanu2507 wants to merge 1 commit into
pgjones:mainfrom
gyanu2507:fix/py314-task-context
Closed

gyanu2507 wants to merge 1 commit into
pgjones:mainfrom
gyanu2507:fix/py314-task-context

Conversation

@gyanu2507

@gyanu2507 gyanu2507 commented Sep 18, 2026 •

Copy link
Copy Markdown

Fixes #351. Same crash as #354.

_run uses asyncio.Runner.run(). On Python 3.14 that task can eager-start, so the first await asyncio.wait_for(...) in worker_serve (lifespan startup) runs with current_task() still None. 3.14's timeout() raises RuntimeError: Timeout should be used inside a task and the worker dies before it binds.

Yield once inside the wrapped main so wait_for / TaskGroup see a real task. Tested _run against wait_for.

Python 3.14 can eager-start the Runner task. wait_for then calls
timeout() with current_task() still None and the worker dies on
startup.

Fixes pgjones#351
@gyanu2507

Copy link
Copy Markdown
Author

Closing this to narrow my open-source work to fewer projects. Anyone is welcome to pick the change up if it's useful.

@gyanu2507 gyanu2507 closed this Nov 9, 2026
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.

Python 3.14 compatibility - TaskGroup, wait_for, and timeout require task context

1 participant