asyncgui

raw JSON →
0.10.1 verified Mon Apr 27 auth: no python

A minimalistic async library focusing on fast responsiveness. Current version 0.10.1, requires Python >=3.10, <4.0. Released regularly with API-breaking changes in minor versions.

pip install asyncgui
error AttributeError: module 'asyncgui' has no attribute 'run_as_main'
cause `run_as_main` was removed in v0.10.0.
fix
Use asyncgui.run() instead.
error TypeError: Task.__init__() got an unexpected keyword argument 'cancel_scope'
cause Cancellation API changed in v0.9.0; `open_cancel_scope` removed.
fix
Use the new cancellation pattern as shown in docs.
error AttributeError: 'Event' object has no attribute 'wait'
cause In v0.7.0, `Event` was reworked. Old code using `.wait()` on Event now fails; you may need `StatefulEvent` or `ExclusiveEvent`.
fix
If you need stateful event, use StatefulEvent. Use ExclusiveEvent for one-shot.
breaking In v0.10.0, `run_as_main` was removed. Use `run()` instead.
fix Replace `run_as_main` with `run`.
breaking In v0.9.0, `open_cancel_scope()` and `disable_cancellation()` were removed. Use new cancellation API or context managers.
fix Migrate to the simplified cancel system; see docs.
breaking In v0.7.0, the `Event` class was completely reworked. Old `Event` behavior is now `Box` (deprecated). `AsyncEvent` renamed to `ExclusiveEvent`, `AsyncBox` to `ExclusiveBox`.
fix Replace old `Event` usage with `Box` or `StatefulEvent`. Use `ExclusiveEvent` instead of `AsyncEvent`.
gotcha `Task` objects must be started with `.start()` or used as async context manager before they execute. Simply creating a Task does not start it.
fix Always call `task.start()` or use `async with Task(coro):`.
deprecated `Box` and `ExclusiveBox` are deprecated since v0.7.2. Use `StatefulEvent` and `ExclusiveEvent` instead.
fix Replace `Box` with `StatefulEvent`, `ExclusiveBox` with `ExclusiveEvent`.

Minimal example showing task creation, event firing, and running with asyncgui's run().

import asyncio
from asyncgui import run, Task, Event, wait_all

async def worker(event):
    print("Worker started, waiting for event...")
    await event.wait()
    print("Worker got event")

async def main():
    event = Event()
    task = Task(worker(event))
    task.start()
    await asyncio.sleep(0.1)
    print("Firing event")
    event.fire()
    await task.join()
    print("Done")

run(main())