python-trio / python-trio/trio

Idea: service nurseries

Open
#1,521 13 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Extracting this idea from #147, because that's a monster thread and this seems worth discussing separately.

Idea: a "service nursery" is one where the background tasks are "services" that don't do anything on their own, but provide some service to the main task. Therefore:

  • background tasks are automatically cancelled when the nursery block exits
  • before the nursery block exits, background tasks are automatically shielded from cancellation (and maybe KeyboardInterrupt?)
  • mayyybe there's some special handling of exception propagation? if in the future we switch to always wrapping nursery exceptions in a multi-error-equivalent (#611), AND multi-errors remain awkward and folks want to avoid them, then we could potentially do that with a service nursery by deeming that background tasks should never fail, so if they do then you get a special BackgroundServiceFailed error or something, and that way the main task body exception doesn't need to be wrapped in a multi-error? Dunno, this seems dubious to me.

Examples that fit this pattern:

Straw man implementation: https://github.com/python-trio/trio/issues/147#issuecomment-455824598

Questions:

  • Are those semantics right?
  • Should the special "service-ness" flag be attached to the nursery, or to individual tasks?
  • open_nursery(service=True) or open_service_nursery()?
  • control-C handling? (see also #733)

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

Start by reading the straw-man implementation linked from #147, then review the related discussions in #147, #611, and #733. Compare the proposed cancellation, shielding, exception, and KeyboardInterrupt semantics with the listed service-nursery examples. Done would require an agreed design and API before implementation begins.

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.