Narrow the API gap between AnyIO and Trio #105
Labels
design
Requires a design decision
help wanted
Extra attention is needed
trio
Involves the trio backend
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()
vstrio.open_file()
anyio.receive_signals()
vstrio.open_signal_receiver()
anyio.run_in_thread()
vstrio.run_sync_in_worker_thread()
anyio.current_default_thread_limiter()
vstrio.current_default_worker_thread_limiter()
The API functions below have issues that need to be discussed.
trio.CancelScope
vsanyio.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()
vsanyio.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 withCancelScope
.trio.MultiError
vsanyio.ExceptionGroup
The long term plan is to unify this under the exceptiongroup library. This task is tracked in issue #17.
trio.from_thread.run()
vsanyio.run_async_from_thread()
I have a couple problems with this:
run()
andrun_sync()
methods? Couldn'trun()
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.
The text was updated successfully, but these errors were encountered: