goodboy / tractor

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

`Context` semantics for cross-actor-task cancellation and overruns #357

Open goodboy opened 1 year ago

goodboy commented 1 year ago

Finally!

This is a rigorous rework of our Context and ContextCancelled semantics to be more like trio.CancelScope for cross-actor linked tasks!

High level mechanics:

Also included is new support and public API for allowing contexts (and their streams) to "allow overruns" (since backpressure isn't really possible without a msg/transport protocol extension): enabling the case where some sender is pushing msgs faster then the other side is receiving them and no error is received on the sender side.

Normally (and by default) the rx side will receive (via RemoteActorError msg) and subsequently raise a StreamOverrun that's been relayed from the sender. The receiver then can decide how to the handle the condition; previously any sent msg delivered that caused an overrun would be discarded.

Instead we now offer a allow_overruns: bool to the Context.open_stream() API which adds a new mode with the following functionality:


Details of implementation:


Possibly still todo: