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
![Quadruped Foundations and System Architecture — Ch.11: Case Studies [EN]](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu66zzbi589sy2737wqzb.png)