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 Common errors
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. Warnings
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`.
Imports
- Task wrong
from asyncgui.task import Taskcorrectfrom asyncgui import Task - Event wrong
from asyncgui.event import Eventcorrectfrom asyncgui import Event - ExclusiveEvent wrong
from asyncgui.exclusive_event import ExclusiveEventcorrectfrom asyncgui import ExclusiveEvent - StatefulEvent
from asyncgui import StatefulEvent - wait_all
from asyncgui import wait_all - wait_any
from asyncgui import wait_any - run wrong
from asyncgui.runner import runcorrectfrom asyncgui import run
Quickstart
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())