Hasty Briefsbeta

Bilingual

Tinyio: A tiny (~200 line) event loop for Python

9 months ago
  • #Event Loop
  • #Python
  • #Asynchronous Programming
  • tinyio is a simple event loop for Python designed as an alternative to asyncio for simpler use-cases.
  • It uses `yield` instead of `await` for coroutine suspension, with the same behavior.
  • Supports waiting on single or multiple coroutines with `yield coro` or `yield [coro1, coro2]`.
  • Errors in any coroutine cancel all coroutines in the event loop, propagating `CancelledError`.
  • Allows running synchronous functions in threads with `tinyio.run_in_thread`.
  • Provides `tinyio.sleep` for delays and handles nested loops without thread restrictions.
  • Simplifies error handling by chaining tracebacks and propagating errors across threads.
  • Designed for robustness with straightforward error semantics, unlike asyncio or trio.
  • Best suited for simple scenarios where complex event loop features are unnecessary.