forked from goodboy/tractor
1.4 KiB
1.4 KiB
Add "infected asyncio mode; a sub-system to spawn and control asyncio actors using trio's guest-mode.
This gets us the following very interesting functionality:
- ability to spawn an actor that has a process entry point of
asyncio.run()by passinginfect_asyncio=TruetoPortal.start_actor()(and friends). - the
asyncioactor embedstriousing guest-mode and starts a maintriotask which runs thetractor.Actor._async_main()entry point engages all the normaltractorruntime IPC/messaging machinery; for all purposes the actor is now running normally on atrio.run(). - the actor can now make one-to-one task spawning requests to the underlying
asyncioevent loop using either of:to_asyncio.run_task()to spawn and run anasynciotask to completion and block until a return value is delivered.async with to_asyncio.open_channel_from():which spawns a task and hands it a pair of "memory channels" to allow for bi-directional streaming between the now SC-linkedtrioandasynciotasks.
The output from any call(s) to asyncio can be handled as normal in trio/tractor task operation with the caveat of the overhead due to guest-mode use.
For more details see the original PR and issue.