Commit Graph

6 Commits (49a07e070ea5d264552cde67f279672c790fa159)

Author SHA1 Message Date
Tyler Goodlet 49a07e070e Go all in on "task manager" naming 2025-03-10 12:33:36 -04:00
Tyler Goodlet 0409566b65 More refinements and proper typing
- drop unneeded (and commented) internal cs allocating bits.
- bypass all task manager stuff if no generator is provided by the
  caller; i.e. just call `.start_soon()` as normal.
- fix `Generator` typing.
- add some prints around task manager.
- wrap in `TaskOutcome.lowlevel_task: Task`.
2025-03-10 12:33:36 -04:00
Tyler Goodlet 8d67af1273 Ensure user-allocated cancel scope just works!
Turns out the nursery doesn't have to care about allocating a per task
`CancelScope` since the user can just do that in the
`@task_scope_manager` if desired B) So just mask all the nursery cs
allocating with the intention of removal.

Also add a test for per-task-cancellation by starting the crash task as
a `trio.sleep_forever()` but then cancel it via the user allocated cs
and ensure the crash propagates as expected 💥
2025-03-10 12:33:36 -04:00
Tyler Goodlet ce33a2d612 Facepalm, don't pass in unecessary cancel scope 2025-03-10 12:33:36 -04:00
Tyler Goodlet f47179239c Do renaming, implement lowlevel `Outcome` sending
As was listed in the many todos, this changes the `.start_soon()` impl
to instead (manually) `.send()` into the user defined
`@task_scope_manager` an `Outcome` from the spawned task. In this case
the task manager wraps that in a user defined (and renamed)
`TaskOutcome` and delivers that + a containing `trio.CancelScope` to the
`.start_soon()` caller. Here the user defined `TaskOutcome` defines
a `.wait_for_result()` method that can be used to await the task's exit
and handle it's underlying returned value or raised error; the
implementation could be different and subject to the user's own whims.

Note that by default, if this was added to `trio`'s core, the
`@task_scope_manager` would simply be implemented as either a `None`
yielding single-yield-generator but more likely just entirely ignored
by the runtime (as in no manual task outcome collecting, generator
calling and sending is done at all) by default if the user does not provide
the `task_scope_manager` to the nursery at open time.
2025-03-10 12:33:36 -04:00
Tyler Goodlet 947db4a2d2 Initial prototype for a one-cancels-one style supervisor, nursery thing.. 2025-03-10 12:33:36 -04:00