tractor
tractor copied to clipboard
Running asyncio actors using "guest mode" vs. anyio task groups
trio recently added "guest mode" a very brilliant solution to integration with foreign event loops and we've used it with great success in piker for charting with Qt.
I'm wondering if it's sensible to create a new actor entry point that could be run using an explicit Nursery.start_aio_actor()? In piker there is a need for something like this being built-in to avoid hoop jumping with trio-asyncio. Guest mode makes a lot of sense since tractor machinery can pretty much run unmodified and can stay written intrio despite being run "on top of" an asyncio loop.
The main comparison is whether to do this versus trying to make anyio "work".
using guest mode
- i/o with
asynciowill likely be done over queues/channels such as in the primary guest mode example - this has the implication that we likely lose any ability for subtask error propagation from
asyncio- note this is still a problem with
anyio(see below)
- note this is still a problem with
uvloopshould be supported (something we don't get withtrio-asyncio)- streaming should mostly work out-of-the box (though we may need to cook up an api for
asynciospecific "wrapping") - "remote"
asyncioasync function entry points may need to be decorated such that the correcttractorentry point can be configured at import time - there may be unforeseen latency in the queue/channel translation
adopting anyio
- internals need to potentially be re-written to use
anyio's task groups, and generally, theanyiocompat apis- I'm personally not huge on this as one of the primary goals for
tractorwas to encourage and motivate use oftrio(which ideally gets us things like rust loop speedups in the core :wink:)
- I'm personally not huge on this as one of the primary goals for
- the implications for maintaining proper cancellation semantics may still be lost:
Tasks spawned by these “native” libraries on backends other than trio are not subject to the cancellation rules enforced by AnyIO
- there may be latency introduced by the compat layer?
- I'm not sure we'll ever have a need for
curiosupport? asynciomay end up adopting SC concepts and apis natively at which pointanyiomay be come somewhat superfluous given that guest mode exists?
I'd appreciate input from others. I'm likely going to experiment with a guest mode shim in piker for now and see if I run into anything dangerous :surfer:
Oh, another thing to keep an eye on is how this all relates with #117 and getting sane subproc spawning working. anyio does have some good effort going on this front.