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

Narrow the API gap between AnyIO and Trio #105

Closed
agronholm opened this issue Mar 22, 2020 · 0 comments
Closed

Narrow the API gap between AnyIO and Trio #105

agronholm opened this issue Mar 22, 2020 · 0 comments
Labels
design Requires a design decision help wanted Extra attention is needed trio Involves the trio backend

Comments

@agronholm
Copy link
Owner

I have received several complaints about the AnyIO's and Trio's APIs differing (to no one's benefit).
I created this issue to discuss which parts of the API could reasonably be changed to match Trio's.
Some of these changes may require backwards incompatible changes.

I have tried to make a list of differences below but feel free to point out any omissions.

The functions which are fully equivalent and could be renamed or aliased without issues:

  • anyio.aopen() vs trio.open_file()
  • anyio.receive_signals() vs trio.open_signal_receiver()
  • anyio.run_in_thread() vs trio.run_sync_in_worker_thread()
  • anyio.current_default_thread_limiter() vs trio.current_default_worker_thread_limiter()

The API functions below have issues that need to be discussed.

trio.CancelScope vs anyio.open_cancel_scope()

Trio itself changed this during after AnyIO's release. Trio used to have an open_cancel_scope() function. Moving this to a class would probably require overriding __new__() to return an instance of a backend specific implementation of this.

trio.open_nursery() vs anyio.create_task_group()

I personally find the term "nursery" unintuitive, and I have not run into it anywhere else. Furthermore, it puzzles me that, although the function is synchronous, it hasn't been replaced by a NurseryManager constructor, like was done with CancelScope.

trio.MultiError vs anyio.ExceptionGroup

The long term plan is to unify this under the exceptiongroup library. This task is tracked in issue #17.

trio.from_thread.run() vs anyio.run_async_from_thread()

I have a couple problems with this:

  1. Why did this require a separate module?
  2. Why are there separate run() and run_sync() methods? Couldn't run() just call the function and, if the return value is a coroutine, await on it?

Additionally, AnyIO does not currently support entering the event loop from outside of worker threads spawned from the event loop thread, mostly due to limitations imposed by Curio which does not support this. I will have to find a good solution to this.

Trio Channels vs AnyIO Streams

This design issue is still open in Trio's own issue tracker.

@agronholm agronholm added help wanted Extra attention is needed trio Involves the trio backend design Requires a design decision labels Mar 22, 2020
agronholm added a commit that referenced this issue May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Requires a design decision help wanted Extra attention is needed trio Involves the trio backend
Projects
None yet
Development

No branches or pull requests

1 participant