tractor icon indicating copy to clipboard operation
tractor copied to clipboard

Running asyncio actors using "guest mode" vs. anyio task groups

Open goodboy opened this issue 5 years ago • 1 comments

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 asyncio will 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)
  • uvloop should be supported (something we don't get with trio-asyncio)
  • streaming should mostly work out-of-the box (though we may need to cook up an api for asyncio specific "wrapping")
  • "remote" asyncio async function entry points may need to be decorated such that the correct tractor entry 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, the anyio compat apis
    • I'm personally not huge on this as one of the primary goals for tractor was to encourage and motivate use of trio (which ideally gets us things like rust loop speedups in the core :wink:)
  • 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 curio support?
  • asyncio may end up adopting SC concepts and apis natively at which point anyio may 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:

goodboy avatar Jun 23 '20 11:06 goodboy

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.

goodboy avatar Jun 23 '20 11:06 goodboy