-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infect asyncio
#121
Merged
Merged
Infect asyncio
#121
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goodboy
commented
Jun 29, 2020
tractor/to_asyncio.py
Outdated
task = asyncio.create_task(_invoke(from_trio, to_trio, coro)) | ||
err = None | ||
|
||
# XXX: I'm not sure this actually does anything... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old; it does.
goodboy
commented
Jun 29, 2020
tractor/to_asyncio.py
Outdated
|
||
# XXX: I'm not sure this actually does anything... | ||
def cancel_trio(task): | ||
"""Cancel the calling ``trio`` task on error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and save any error.
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Jul 4, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
5 tasks
goodboy
force-pushed
the
infect_asyncio
branch
4 times, most recently
from
July 30, 2020 13:46
cea0b0b
to
69dad96
Compare
goodboy
force-pushed
the
multiproc_debug
branch
from
August 4, 2020 01:16
91a9117
to
ed68a2d
Compare
goodboy
force-pushed
the
multiproc_debug
branch
from
August 4, 2020 16:02
ed68a2d
to
0925fee
Compare
goodboy
force-pushed
the
multiproc_debug
branch
2 times, most recently
from
August 13, 2020 18:43
62f74b9
to
e483042
Compare
goodboy
force-pushed
the
infect_asyncio
branch
from
August 13, 2020 18:43
894b997
to
a262d03
Compare
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Sep 1, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Sep 2, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Sep 2, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Sep 2, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
goodboy
force-pushed
the
infect_asyncio
branch
from
September 12, 2020 15:52
a262d03
to
48d9c6e
Compare
goodboy
force-pushed
the
multiproc_debug
branch
from
September 24, 2020 14:13
8de9493
to
9e1d9a8
Compare
goodboy
force-pushed
the
infect_asyncio
branch
from
September 24, 2020 14:56
48d9c6e
to
4059c2f
Compare
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Sep 26, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
goodboy
added a commit
to pikers/piker
that referenced
this pull request
Sep 29, 2020
Infected `asyncio` support is being added to `tractor` in goodboy/tractor#121 so delegate to all that new machinery. Start building out an "actor-aware" api which takes care of all the `trio`-`asyncio` interaction for data streaming and request handling. Add a little (shudder) method proxy system which can be used to invoke client methods from another actor. Start on a streaming api in preparation for real-time charting.
goodboy
force-pushed
the
infect_asyncio
branch
2 times, most recently
from
October 7, 2020 09:54
3dd4739
to
36ec668
Compare
goodboy
force-pushed
the
multiproc_debug
branch
from
October 14, 2020 01:02
bcb2714
to
8b4e2bb
Compare
Pull the common `asyncio` -> `trio` error translation logic into a common context manager and don't expect a final result to be captured when using `open_channel_from()` since it's a manager interface and it would be clunky to try and deliver some "final result" after exit.
Wraps the pairs of underlying `trio` mem chans and the `asyncio.Queue` with this new composite which will be delivered from `open_channel_from()`. This allows for both sending and receiving values from the `asyncio` task (2 way msg passing) as well controls for cancelling or waiting on the task. Factor `asyncio` translation and re-raising logic into a new closure which is run on both `trio` side error handling as well as on normal termination to avoid missing `asyncio` errors even when `trio` task cancellation is handled first. Only close the `trio` mem chans on `trio` task termination *iff* the task was spawned using `open_channel_from()`: - on `open_channel_from()` exit, mem chan closure is the desired semantic - on `run_task()` we normally only return a single value or error and if the channel is closed before the error is raised we may propagate a `trio.EndOfChannel` instead of the desired underlying `asyncio` task's error
For whatever reason `trio` seems to be swallowing this exception when raised in the `trio` task so instead wrap it in our own non-base exception type: `AsyncioCancelled` and raise that when the `asyncio` task cancels itself internally using `raise <err> from <src_err>` style. Further don't bother cancelling the `trio` task (via cancel scope) since we we can just use the recv mem chan closure error as a signal and explicitly lookup any set asyncio error.
Better encapsulate all the mem-chan, Queue, sync-primitives inside our linked task channel in order to avoid `mypy`'s complaints about monkey patching. This also sets footing for adding an `asyncio`-side channel API that can be used more like this `trio`-side API.
goodboy
force-pushed
the
infect_asyncio
branch
from
December 17, 2021 14:41
ca98a3d
to
9b4cdb0
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
README blurb summarizing this new feature.
What I hope to be a successful attempt at solving #120.
This gets us the following very interesting functionality:
asyncio.run()
asyncio
actor embedstrio
using the new guest mode which then enters thetractor.Actor._async_main()
entry point thus engaging all the std IPC machinerytractor.to_asyncio.run()
method which allows spawning tasks in the hostasyncio
loop and waiting/streaming the result(s) back into thetrio
taskIt ended up being possible to accomplish per task error propagation by simply doing a little state passing inside the callback passed to
asyncio.Task.add_done_callback()
and thus not requiring the use ofanyio
. In fact I'm not even sure it's possible to do this with the task groups offered byanyio
due to the nature of spawningasyncio
tasks fromtrio
tasks and providing an api to acquire the results on demand.The main idea here is that a new
tractor
actor can be spawned and async functions that will run undertrio
can make calls to spawnasyncio
tasks using the newtractor.to_asyncio.run()
routine which acts basically liketractor.Portal.run()
but without any IPC stuff going on underneath. All IPC is done as normal once results are back in the (embedded)trio
task.This basically makes
tractor
integration withasyncio
frameworks a super cinch now :)ping @njsmith @oremanj.
If either of you have time to look at this and tell if there's a more trionic way it'd be grealy appreciated 😸
Further things to be done:
- [ ] potentially support the existingtrip is being removed in First attempt at removing trip & updating hazmat -> lowlevel #127.trip
backend using the even newer inside-out-guest-mode (Inside-out guest mode python-trio/trio#1652) though the plan is to deprecate this anyway (Let's roll our own subproc spawner ("the way the experts would") #117)[ ] using the even newer inside-out-guest-mode (Inside-out guest mode python-trio/trio#1652)?not yet approved in trio core.Provisional test list:
[ ] call async generator and stream from itno longer supported[ ]unneeded with new api@stream
compatibility?[ ]don't member why i wrote thistrio_trio
/from_trio
injectionPortal.cancel_actor()
trio.move_on_after()
around actor nurserytrio
cancellationto_asyncio.open_channel_from():