Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial prototype for trio.Nursery per-task-scope-mangement via a user defined single-yield-generator function 😎 #363

Draft
wants to merge 8 commits into
base: ctx_cancel_semantics_and_overruns
Choose a base branch
from

Commits on May 19, 2023

  1. Configuration menu
    Copy the full SHA
    5fc8fa5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b485871 View commit details
    Browse the repository at this point in the history
  3. 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.
    goodboy committed May 19, 2023
    Configuration menu
    Copy the full SHA
    65c5d7d View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    f23b5b8 View commit details
    Browse the repository at this point in the history
  5. 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 💥
    goodboy committed May 19, 2023
    Configuration menu
    Copy the full SHA
    56882b6 View commit details
    Browse the repository at this point in the history
  6. 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`.
    goodboy committed May 19, 2023
    Configuration menu
    Copy the full SHA
    940e65f View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    e0c888f View commit details
    Browse the repository at this point in the history
  8. Add debug_mode: bool control to task mngr

    Allows dynamically importing `pdbp` when enabled and a way for
    eventually linking with `tractor`'s own debug mode flag.
    goodboy committed May 19, 2023
    Configuration menu
    Copy the full SHA
    c7e27ad View commit details
    Browse the repository at this point in the history