xiio

really simple async runtime
git clone https://git.ce9e.org/xiio.git

NameSize
.github/workflows/main.yml853B
LICENSE1072B
README.md2404B
pyproject.toml426B
tests/test_compat.py1924B
tests/test_core.py3969B
tests/test_multiplex.py4971B
tests/test_signals.py655B
tests/test_subprocess.py860B
tests/test_threads.py903B
tests/utils.py765B
xiio/__init__.py561B
xiio/compat.py1542B
xiio/core.py5112B
xiio/multiplex.py2855B
xiio/signals.py1021B
xiio/subprocess.py1152B
xiio/threads.py1920B

xiio - really simple async runtime

xiio (Ξ-I/O) is yet another async runtime for Python, like asyncio or trio. Both of these libraries have ~10k lines of code, while this one has a few hundred lines. So I guess it is fair to say that it is really simple.

Usage

import sys
import xiio


async def greet(name):
    await xiio.sleep(len(name) / 10)
    print(f'Hello, {name}!')


async def main():
    async with xiio.timeout(10):
        name1 = (await xiio.read(sys.stdin, 32)).decode()
        name2 = (await xiio.read(sys.stdin, 32)).decode()

        await xiio.gather([
            greet(name1),
            greet(name2),
        ])


xiio.run(main())

Structured Concurrency

Similar to nurseries in trio and task groups in asyncio, xiio provides a low level primitive that controls the lifetime of subtasks. For example, gather() is just a higher level abstraction on top of that:

async def gather(coros):
    async with TaskGroup() as tg:
        tasks = [tg.add_task(coro) for coro in coros]
    return [task.result for task in tasks]

Task groups in xiio have the following properties:

Design

I spent quite some time creating meaningful commits. So if you want to understand why all the individual pieces are there and how they fit together, I encourage you to check the commit history.