A thin layer that helps to build async/await-based APIs using callback-based APIs
Project description
AsyncGui
A thin layer that helps to wrap a callback-style API in an async/await-style API.
How to use
Despite its name, the application of asyncgui is not limited to gui programs.
You can wrap any kind of callback-based APIs in it.
The simplest example of it would be sched,
whose the whole feature is timer.
All you need is just few lines of code:
import sched
import asyncgui
s = sched.scheduler()
# Wrapping 'scheduler.enter()'
async def sleep(duration, *, priority=10):
sig = asyncgui.ISignal()
event = s.enter(duration, priority, sig.set)
try:
await sig.wait()
except asyncgui.Cancelled:
s.cancel(event)
raise
async def main():
print('A')
await sleep(1) # Now you can sleep in an async-manner
print('B')
await sleep(1)
print('C')
asyncgui.start(main())
s.run()
And you already have structured concurrency APIs as well:
async def print_numbers():
for i in range(10):
await sleep(.1)
print(i)
async def print_letters():
for c in "ABCDE":
await sleep(.1)
print(c)
async def main():
# Let print_letters() and print_numbers() race.
# As soon as any of them finishes, the other one gets cancelled.
tasks = await asyncgui.wait_any(print_letters(), print_numbers())
if tasks[0].finished:
print("print_letters() won")
else:
print("print_numbers() won")
print('main end')
A
0
B
1
C
2
D
3
E
print_letters() won
main end
Installation
It's recommended to pin the minor version, because if it changed, it means some important breaking changes occurred.
poetry add asyncgui@~0.6
pip install "asyncgui>=0.6,<0.7"
Tested on
- CPython 3.8
- CPython 3.9
- CPython 3.10
- CPython 3.11
- CPython 3.12 (3.12.1 or later)
Async-libraries who relies on this
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncgui-0.6.1.tar.gz.
File metadata
- Download URL: asyncgui-0.6.1.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.4.0-169-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baaf9ca434eebed2d5c86f68cf5c7586f46da1979564b981167de9be8190a975
|
|
| MD5 |
7c2149328057de239bb945ccb0f20f60
|
|
| BLAKE2b-256 |
07d9dcd09c0788227c5cdbbd752c67f156d7b274095ca387e925f2a98ba37ecd
|
File details
Details for the file asyncgui-0.6.1-py3-none-any.whl.
File metadata
- Download URL: asyncgui-0.6.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.4.0-169-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cb6cd12f595329abf90444873350e6e42f92dce9028c9096f6feefd723767e0
|
|
| MD5 |
87798475f8602d3e27b9157baa398e14
|
|
| BLAKE2b-256 |
4f0548c7a08d0114f131dca6994e5fe4e46856cd9c99604039b3adeb70a59e9f
|