python-trio / python-trio/trio
start() shouldn't support multiple tasks in the old_nursery
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
Currently, Nursery.start() is implemented internally by opening a private nursery and starting the new task there, and TaskStatus.started() moves all tasks from that private nursery (the "old_nursery") to the task's final home ("new_nursery", the nursery whose start() method was called). In theory, there should only be one task in the old nursery, since the nursery isn't exposed anywhere outside the body of start() for anyone to be able to start more. In practice, it's possible to access the old nursery via current_task().parent_nursery in the newly-started task, so we may have some users who are starting more tasks there, maybe not even realizing that it's not the same nursery on which start() was called. This currently works fine, but it's confusing and makes it hard to implement extensions to the nursery semantics such as #1521.
Since this works now, we probably want a deprecation period. The purpose of this issue is mostly to have a number to put in the deprecation message. If your code runs into this, ideally you would refactor it to pass a nursery around explicitly rather than assuming you can always start new tasks in your parent nursery. If that's not possible for some reason, you can use task.eventual_parent_nursery or task.parent_nursery to determine the parent nursery that will prevail once the start() call completes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading Nursery.start() and TaskStatus.started(), focusing on the old_nursery and new_nursery handling described here. Trace current_task().parent_nursery and eventual_parent_nursery to understand the compatibility path. Done means the multiple-task behavior is deprecated as intended and the documented explicit-nursery alternative remains available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100