Python's asyncio ecosystem, especially its tools for crossing between asynchronous and blocking code, is broken in some frustrating ways.

I made a library, "async-anywhere", to help with a few common issues in this area. It contains:

1. AwaitableFuture, a future which can be blocked on or awaited, from anywhere, any number of times.

2. EventLoopExecutor, a worker backed by a single thread that runs async code on a captive event loop, and produces AwaitableFutures for interacting with jobs.

3. StateTracker, a simple state machine which allows observers to wait on and react to state transitions from anywhere.

Those primitives are fork-safe, thread-safe, competitively performant, do cancellations in a sane way, and handle many different async/sync/threaded contexts and assumptions well.

Docs: https://async-anywhere.readthedocs.io

Source (MIT license): https://github.com/zbentley/async-anywhere

Rationale/blog post: https://blog.zacbentley.com/post/async-anywhere/


Comments URL: https://news.ycombinator.com/item?id=50722290

Points: 5

# Comments: 0