goodboy / tractor

A distributed, structured concurrent runtime for Python (and friends)
GNU Affero General Public License v3.0
258 stars 12 forks source link

Injecting `Context._scope: trio.Nursery` errors, probably a `ContextCancelled` to start #368

Open goodboy opened 9 months ago

goodboy commented 9 months ago

Writing up some much more detailed tests for remote actor cancellation as part of #357 has me thinking again about how it'd be nice to be able to inject our own subtype of .trio.Cancelled into each internal nursery / scope (on each side of an inter-actor-task context).

That is @tractor.context and Context.open_context() tasks raise a ContextCancelled on their next checkpoint when our runtime desires to indicate a cancellation condition that was triggered by either Actor.cancel_actor() or Context.cancel() (and/or error bubbling over IPC?) from one side to the other. This would in theory make cross process task supervision easier to implement as well as make it possible to allow the @context side task able to handle remote cancellation requests (more) granular-ly and possibly specially?

A further handy use case would be overriding the CancelScope.__exit__() to allow hiding its stack frame in the pdb repl; something that's handy if you want to shield a pause point like:

trio.CancelScope(shield=True):
  await tractor.pause()

and hide the exit frame on REPL initial entry. (at least this seemed to still be a problem last time i tried to implement such a thing doing .pause(shield=True))


Gitter community suggestions

(Mostly from @oremanj yet again :joy:)


ToDo: