Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: async-anywhere, a Python library for crossing between async/sync code
5 points by zbentley 4 hours ago | past | favorite | discuss
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/

 help





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: