python-trio / python-trio/trio

Idea: unbound nurseries?

Open
#1,597 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design discussion
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

If it was a good idea for cancel scopes (#607)...

I got to thinking about this due to the hoops that #1579 had to jump through. I've also occasionally encountered cases where I wanted to push a nursery into a background task and later spawn things into it, which currently requires an awkward dance with start().

The idea here would be:

  • You can construct a nursery just as trio.Nursery() with no arguments.
  • The tasks inside the nursery only run once it's bound to an async with block.
  • If you call start_soon() before the async with block is entered, the Task is still created but it's not added to the runq yet.
  • If you call start() before the async with block is entered, the new task starts up like normal, but blocks at its first checkpoint after started() until the target nursery is bound.

Is this a good idea at all? If so, are the above semantics the ones we would want?

I'm significantly less convinced this is a good idea for nurseries than that it is one for cancel scopes, especially because "what happens if no one ever binds the nursery?". But I wanted to throw it out there.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the existing trio.Nursery API and the discussions in issues #607 and #1579. This issue is complete only after the project decides whether unbound nurseries are desirable and defines the binding, start_soon(), start(), and never-bound semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.