Skip to content
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

Use trio memory channels! #56

Merged
merged 12 commits into from
Feb 21, 2019
Merged

Use trio memory channels! #56

merged 12 commits into from
Feb 21, 2019

Conversation

goodboy
Copy link
Owner

@goodboy goodboy commented Feb 16, 2019

trio deprecated the old Queue in 0.11.0 and introduced the new trio.open_memory_channel() system. Adopt this throughout the core and adjust all tests.

In other fun news, we were also suffering from a super subtle bug in Python itself, namely:
https://bugs.python.org/issue32526

This was the root cause of a slew of issues in some UI work in piker.

It turns out (at least with trio) asyn gen functions are not task safe and can cause all sorts of strange issues if operated on by multiple tasks. Thanks to in depth diagnosis on the gitter channel, the alternative is to introduce an async iterator derivative of trio.abc.ReceiveChannel which wraps an underlying receive memory channel: the deliverer of iter-actor messages to actor-local tasks.

Todo:

  • update docs examples to use memchans
  • limit trio to > 0.10.0?

Ping @oremanj @njsmith @vodik!
Please feel free to tear this right apart.

@oremanj @njsmith the main part I would very much appreciate your eyes on is the new async iterator wrapper.

Tyler Goodlet added 8 commits February 14, 2019 13:08
For now stop `.aclose()`-ing all async gens on portal close since it can
cause hangs and other weird behaviour if another task operates on the
same instance.

See https://bugs.python.org/issue32526.
In combination with `.aclose()`-ing the async gen instance returned from
`Portal.run()` this demonstrates the python bug:
https://bugs.python.org/issue32526

I've commented out the line that triggers the bug for now since this
case provides motivation for adding our own `trio.abc.ReceiveMemoryChannel`
implementation to be used instead of async gens directly (returned from
`Portal.run()`) since the latter is **not** task safe.
As mentioned in prior commits there's currently a bug in Python that
make async gens **not** task safe. Since this is the core cause of almost
all recent problems, instead implement our own async iterator derivative of
`trio.abc.ReceiveChannel` by wrapping a `trio._channel.MemoryReceiveChannel`.
This fits more natively with the memory channel API in ``trio`` and adds
potentially more flexibility for possible bidirectional inter-actor streaming
in the future.

Huge thanks to @oremanj and of course @njsmith for guidance on this one!
tractor/_portal.py Outdated Show resolved Hide resolved
tractor/_portal.py Outdated Show resolved Hide resolved
@goodboy goodboy merged commit a927966 into master Feb 21, 2019
@goodboy goodboy deleted the trio_memchans branch August 19, 2021 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant