Skip to content

start() shouldn't support multiple tasks in the old_nursery #1599

Open
@oremanj

Description

@oremanj

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions