python-trio / python-trio/trio
Idea: service nurseries
Nobody has claimed this yet.
- 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
BackgroundServiceFailederror 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:
- Trio's "system" nursery
- The background nursery that trio-websocket creates for each connection, or any other protocol that requires some background task to drive the socket
- The
nurseryfixture in pytest-trio - Independently suggested by @matham at https://gitter.im/python-trio/general?at=5ebceeaf2cf0da0ad90004d4
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)oropen_service_nursery()?- control-C handling? (see also #733)
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 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