Skip to main content

TonIO

TonIO is a multi-threaded async runtime for free-threaded Python, built in Rust on top of the mio crate, and inspired by tinyio, trio and tokio.

Warning: TonIO is currently a work in progress and in alpha state. The APIs are subtle to breaking changes.

Note: TonIO is available on free-threaded Python and Unix systems only.

TonIO supports both using yield and the more canonical async/await notations, with the latter being available as part of the tonio.colored module. Following code snippets show both the usages.

Warning: despite the fact TonIO supports async and await notations, it's not compatible with any asyncio object like futures and tasks. The TonIO-Monkey project provides patches for some popular asyncio packages.

In a nutshell

yield syntax

import tonio

def wait_and_add(x: int) -> int:
    yield tonio.sleep(1)
    return x + 1

def foo():
    four, five = yield tonio.spawn(
        wait_and_add(3), 
        wait_and_add(4)
    )
    return four, five

out = tonio.run(foo())
assert out == (4, 5)

await syntax

import tonio.colored as tonio

async def wait_and_add(x: int) -> int:
    await tonio.sleep(1)
    return x + 1

async def foo():
    four, five = await tonio.spawn(
        wait_and_add(3), 
        wait_and_add(4)
    )
    return four, five

out = tonio.run(foo())
assert out == (4, 5)

Usage

Entrypoint

Every TonIO program consist of an entrypoint, which should be passed to the run method:

yield syntax

import tonio

def main():
    yield
    print("Hello world")

tonio.run(main())

await syntax

import tonio.colored as tonio

async def main():
    await tonio.yield_now()
    print("Hellow world")

tonio.run(main())

TonIO also provides a main decorator, thus we can rewrite the previous example as:

yield syntax

import tonio

@tonio.main
def main():
    yield
    print("Hello world")

main()

await syntax

import tonio.colored as tonio

@tonio.main
async def main():
    await tonio.yield_now()
    print("Hello world")

main()

Note: as you can see the colored module provides the additional yield_now coroutine, a quick way to define a suspension point, given you cannot just yield as in the non-colored notation.

Note: both run and main can only be called once per program. To run the runtime multiple times in the same program, follow the section below.

Manually managing the runtime

TonIO also provides the runtime function, to manually manage the runtime lifecycle:

import tonio

def _run1():
    ...

async def _run2():
    ...

def main():
    runtime = tonio.runtime()
    runtime.run_until_complete(_run1())
    runtime.run_until_complete(_run2())

Runtime options

The run, main and runtime methods accept options, specifically:

option name description default
context enable contextvars usage in coroutines False
signals list of signals to listen to
threads Number of runtime threads # of CPU cores
blocking_threadpool_size Maximum number of blocking threads 128
blocking_threadpool_idle_ttl Idle timeout for blocking threads (in seconds) 30

Events

The core object in TonIO is Event. It's basically a wrapper around an atomic boolean flag, initialised with False. Event provides the following methods:

  • is_set(): return the value of the flag
  • set(): set the flag to True
  • clear(): set the flag to False
  • wait(timeout=None): returns a coroutine you can yield on that unblocks when the flag is set to True or the timeout expires. Timeout is in seconds.

yield syntax

import tonio

@tonio.main
def main():
    event = tonio.Event()

    def setter():
        yield tonio.sleep(1)
        event.set()

    tonio.spawn(setter())
    yield event.wait()

await syntax

import tonio.colored as tonio

@tonio.main
async def main():
    event = tonio.Event()

    async def setter():
        await tonio.sleep(1)
        event.set()

    tonio.spawn(setter())
    await event.wait()

Spawning tasks

TonIO provides the spawn method to schedule new coroutines onto the runtime:

yield syntax

import tonio

def doubv(v):
    yield
    return v * 2

@tonio.main
def main():
    parallel = tonio.spawn(doubv(2), doubv(3))
    v3 = yield doubv(4)
    v1, v2 = yield parallel
    print([v1, v2, v3])

await syntax

import tonio.colored as tonio

async def doubv(v):
    await tonio.yield_now()
    return v * 2

@tonio.main
async def main():
    parallel = tonio.spawn(doubv(2), doubv(3))
    v3 = await doubv(4)
    v1, v2 = await parallel
    print([v1, v2, v3])

Coroutines passed to spawn get schedule onto the runtime immediately. Using yield or await on the return value of spawn just waits for the coroutines to complete and retreive the results.

Blocking tasks

TonIO provides the spawn_blocking method to schedule blocking operations onto the runtime:

yield syntax

import tonio

def read_file(path):
    with open(file, "r") as f:
        return f.read()

@tonio.main
def main():
    file_data = yield tonio.spawn_blocking(
        read_file, 
        "sometext.txt"
    )

await syntax

import tonio.colored as tonio

def read_file(path):
    with open(file, "r") as f:
        return f.read()

@tonio.main
async def main():
    file_data = await tonio.spawn_blocking(
        read_file, 
        "sometext.txt"
    )

Running tasks from synchronous contexts

TonIO provides the block_on method to spawn coroutines from a synchronous context. It works the same way of spawn, except it accepts a single coroutine and it blocks the current thread until the coroutine is completed.

Warning: using block_on from within a coroutine might produce a runtime deadlock.

Map utilities

TonIO provides the map and map_blocking utilities to spawn the same operation with an iterable of parameters:

yield syntax

import tonio

accum = []

def task(no):
    yield tonio.sleep(0.5)
    accum.append(no * 2)

@tonio.main
def main():
    yield tonio.map(task, range(4))

await syntax

import tonio.colored as tonio

accum = []

async def task(no):
    await tonio.sleep(0.5)
    accum.append(no * 2)

@tonio.main
async def main():
    await tonio.map(task, range(4))

Completion-based iterators

TonIO provides the as_completed utility to iterate over task results based on completion order:

yield syntax

import tonio

def _sleep(v):
    yield tonio.sleep(v)
    return v

@tonio.main
def main():
    vals = []
    for task in tonio.as_completed(
        _sleep(0.5),
        _sleep(0.1),
        _sleep(0.3),
    ):
        vals.append(yield task)

await syntax

import tonio.colored as tonio

async def _sleep(v):
    await tonio.sleep(v)
    return v

@tonio.main
async def main():
    vals = []
    async for val in tonio.as_completed(
        _sleep(0.5),
        _sleep(0.1),
        _sleep(0.3),
    ):
        vals.append(val)

Scopes and cancellations

TonIO provides a scope context, that lets you cancel work spawned within it:

yield syntax

import tonio

def slow_push(target, sleep):
    yield tonio.sleep(sleep)
    target.append(True)

@tonio.main
def main():
    values = []
    with tonio.scope() as scope:
        scope.spawn(_slow_push(values, 0.1))
        scope.spawn(_slow_push(values, 2))
        yield tonio.sleep(0.2)
        scope.cancel()
    yield scope()
    assert len(values) == 1

await syntax

import tonio.colored as tonio

async def slow_push(target, sleep):
    await tonio.sleep(sleep)
    target.append(True)

@tonio.main
async def main():
    values = []
    async with tonio.scope() as scope:
        scope.spawn(_slow_push(values, 0.1))
        scope.spawn(_slow_push(values, 2))
        await tonio.sleep(0.2)
        scope.cancel()
    assert len(values) == 1

When you yield on the scope, it will wait for all the spawned coroutines to end. If the scope was canceled, then all the pending coroutines will be canceled.

Note: as you can see, the colored version of scope doesn't require to be awaited, as it will yield when exiting the context.

Select first completing task

TonIO also provides a select utility to cancel remaining work on the first completing task:

yield syntax

import tonio

def slow_push(target, sleep):
    yield tonio.sleep(sleep)
    target.append(True)

@tonio.main
def main():
    values = []
    yield tonio.select(
        _slow_push(values, 0.1),
        _slow_push(values, 2)
    )
    assert len(values) == 1

await syntax

import tonio.colored as tonio

async def slow_push(target, sleep):
    await tonio.sleep(sleep)
    target.append(True)

@tonio.main
async def main():
    values = []
    await tonio.select(
        _slow_push(values, 0.1),
        _slow_push(values, 2)
    )
    assert len(values) == 1

Time-related functions

  • tonio.time.time(): a function returning the runtime's clock (in seconds, microsecond resolution)
  • tonio.time.sleep(delay): a coroutine you can yield on to sleep (delay is in seconds)
  • tonio.time.timeout(coro, timeout): a coroutine you can yield on returning a tuple (output, success). If the coroutine succeeds in the given time then the pair (output, True) is returned. Otherwise this will return (None, False).

Note: time.sleep is also exported to the main tonio module.

Note: all of the above functions are also present in tonio.colored.time module.

Scheduling work

TonIO provides the time.interval function to create interval objects you can yield on a scheduled basis:

yield syntax

import tonio
from tonio import time

def some_task():
    ...

def scheduler():
    interval = time.interval(1)
    while True:
        yield interval.tick()
        tonio.spawn(some_task())

@tonio.main
def main():
    tonio.spawn(scheduler())
    # do some other work

await syntax

import tonio.colored as tonio
from tonio.colored import time

async def some_task():
    ...

async def scheduler():
    interval = time.interval(1)
    while True:
        await interval.tick()
        tonio.spawn(some_task())

@tonio.main
async def main():
    tonio.spawn(scheduler())
    # do some other work

The interval method first argument is the interval in seconds resolution, and the method also accepts an optional at argument, to delay the first execution at a specific time (from the runtime's clock perspective):

from tonio import time

# tick every 500ms, with the first tick happening in 5 seconds from now
interval = time.interval(0.5, time.time() + 5)

Synchronization primitives

Synchronization primitives are exposed in the tonio.sync module.

Lock

Implements a classic mutex, or a non-reentrant, single-owner lock for coroutines:

yield syntax

import tonio
from tonio import sync

@tonio.main
def main():
    # counter can't go above 1
    counter = 0

    def _count(lock):
        nonlocal counter
        with (yield lock()):
            counter += 1
            yield
            counter -= 1
    
    lock = sync.Lock()
    yield tonio.spawn(*[
        _count(lock)
        for _ in range(10)
    ])

await syntax

import tonio.colored as tonio
from tonio.colored import sync

@tonio.main
async def main():
    # counter can't go above 1
    counter = 0

    async def _count(lock):
        nonlocal counter
        async with lock:
            counter += 1
            await tonio.yield_now()
            counter -= 1
    
    lock = sync.Lock()
    await tonio.spawn(*[
        _count(lock)
        for _ in range(10)
    ])

The Lock object also implements an or_raise method, that will immediately fail when the lock cannot be acquired:

from tonio.exceptions import WouldBlock

try:
    with lock.or_raise():
        ...
except WouldBlock:
    ...

Semaphore

A semaphore for coroutines:

yield syntax

import tonio
from tonio import sync

@tonio.main
def main():
    # counter can't go above 2
    counter = 0

    def _count(semaphore):
        nonlocal counter
        with (yield semaphore()):
            counter += 1
            yield
            counter -= 1
    
    semaphore = sync.Semaphore(2)
    yield tonio.spawn(*[
        _count(semaphore)
        for _ in range(10)
    ])

await syntax

import tonio.colored as tonio
from tonio.colored import sync

@tonio.main
async def main():
    # counter can't go above 2
    counter = 0

    async def _count(semaphore):
        nonlocal counter
        async with semaphore:
            counter += 1
            await tonio.yield_now()
            counter -= 1
    
    semaphore = sync.Semaphore(2)
    await tonio.spawn(*[
        _count(semaphore)
        for _ in range(10)
    ])

As for locks, the Semaphore object also implements an or_raise method, that will immediately fail when the lock cannot be acquired:

from tonio.exceptions import WouldBlock

try:
    with semaphore.or_raise():
        ...
except WouldBlock:
    ...

The Semaphore object also implements a tokens method, that returns the number of available tokens.

Barrier

A barrier for coroutines:

yield syntax

import tonio
from tonio import sync

@tonio.main
def main():
    barrier = sync.Barrier(3)
    count = 0

    def _start_at_3():
        nonlocal count
        count += 1
        i = yield barrier.wait()
        assert count == 3
        return i

    yield tonio.spawn(*[
        _start_at_3()
        for _ in range(3)
    ])

await syntax

import tonio.colored as tonio
from tonio.colored import sync

@tonio.main
async def main():
    barrier = sync.Barrier(3)
    count = 0

    async def _start_at_3():
        nonlocal count
        count += 1
        i = await barrier.wait()
        assert count == 3
        return i

    await tonio.spawn(*[
        _start_at_3()
        for _ in range(3)
    ])

The Barrier object also implements a value method, which returns the current value of the barrier.

Channels

Multi-producer multi-consumer channels for inter-coroutine communication.

The tonio.sync.channel module provides both a channel and an unbounded constructors.
The main difference between bounded and unbounded channels, as the names suggest, is that while the first will suspend sending messages once the specified length is reached, and it will resume accepting messages once the existing buffer is consumed, the latter will always accept new messages. That's also why, the sender part of a bounded channel is async, while in the unbounded is not.

Bounded channel

yield syntax

import tonio
from tonio import sync
from tonio.sync import channel

def producer(sender, barrier, offset):
    for i in range(20):
        message = offset + 1
        yield sender.send(message)
    yield barrier.wait()

def consumer(receiver):
    while True:
        try:
            message = yield receiver.receive()
            print(message)
        except Exception:
            break

@tonio.main
def main():
    def close(sender, barrier):
        yield barrier.wait()
        sender.close()

    sender, receiver = channel.channel(2)
    barrier = sync.Barrier(3)
    yield tonio.spawn(*[
        producer(sender, barrier, 100),
        producer(sender, barrier, 200),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        close(sender, barrier),
    ])

await syntax

import tonio.colored as tonio
from tonio.colored import sync
from tonio.colored.sync import channel

async def producer(sender, barrier, offset):
    for i in range(20):
        message = offset + 1
        await sender.send(message)
    await barrier.wait()

async def consumer(receiver):
    while True:
        try:
            message = await receiver.receive()
            print(message)
        except Exception:
            break

@tonio.main
async def main():
    async def close(sender, barrier):
        await barrier.wait()
        sender.close()

    sender, receiver = channel.channel(2)
    barrier = sync.Barrier(3)
    await tonio.spawn(*[
        producer(sender, barrier, 100),
        producer(sender, barrier, 200),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        close(sender, barrier),
    ])
Unbounded channel

yield syntax

import tonio
from tonio import sync
from tonio.sync import channel

def producer(sender, barrier, offset):
    for i in range(20):
        message = offset + 1
        sender.send(message)
    yield barrier.wait()

def consumer(receiver):
    while True:
        try:
            message = yield receiver.receive()
            print(message)
        except Exception:
            break

@tonio.main
def main():
    def close(sender, barrier):
        yield barrier.wait()
        sender.close()

    sender, receiver = channel.unbounded()
    barrier = sync.Barrier(3)
    yield tonio.spawn(*[
        producer(sender, barrier, 100),
        producer(sender, barrier, 200),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        close(sender, barrier),
    ])

await syntax

import tonio.colored as tonio
from tonio.colored import sync
from tonio.colored.sync import channel

async def producer(sender, barrier, offset):
    for i in range(20):
        message = offset + 1
        sender.send(message)
    await barrier.wait()

async def consumer(receiver):
    while True:
        try:
            message = await receiver.receive()
            print(message)
        except Exception:
            break

@tonio.main
async def main():
    async def close(sender, barrier):
        await barrier.wait()
        sender.close()

    sender, receiver = channel.unbounded()
    barrier = sync.Barrier(3)
    await tonio.spawn(*[
        producer(sender, barrier, 100),
        producer(sender, barrier, 200),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        consumer(receiver),
        close(sender, barrier),
    ])

Network module

Network primitives are exposed under the tonio.net module.

Streams

The high-level network primitives in TonIO are centered aroud the SocketStream and SocketListener objects.

The SocketListener object implements an accept coroutine which returns a SocketStream object.
The SocketStream object implements the send_all and receive_some coroutines to send and receive data.
Both objects implement a close method to shutdown the underlying socket.

You can create and interact with the above objects using some high-level helpers in the net module, specifically:

  • open_tcp_stream: a coroutine to open a SocketStream connected to a TCP endpoint
  • open_unix_socket: a coroutine to open a SocketStream connected to a Unix socket
  • open_tcp_listeners: a coroutine to initialise SocketListener objects
  • open_unix_listener: a coroutine to initialise a SocketListener on a Unix socket path
  • serve_listeners: a coroutine to spawn SocketListener accept loops targeting a handler
  • serve_tcp: a coroutine that joins open_tcp_listeners and serve_listeners in one call
  • serve_unix: a coroutine that joins open_unix_listener and serve_listeners in one call

yield syntax

from tonio.net import open_tcp_stream, serve_tcp

def server():
    yield serve_tcp(
        server_handle, 
        host='127.0.0.1', 
        port=8000
    )

def server_handle(stream):
    # receive some data
    data = yield stream.receive_some()

def client():
    stream = yield open_tcp_stream(
        host='127.0.0.1', 
        port=8000
    )
    # send some data
    yield stream.send_all("message")

await syntax

from tonio.colored.net import open_tcp_stream, serve_tcp

async def server():
    await serve_tcp(
        server_handle, 
        host='127.0.0.1', 
        port=8000
    )

async def server_handle(stream):
    # receive some data
    data = await stream.receive_some()

async def client():
    stream = await open_tcp_stream(
        host='127.0.0.1', 
        port=8000
    )
    # send some data
    await stream.send_all("message")

Unix domain sockets use the same objects, with serve_unix and open_unix_socket:

yield syntax

from tonio.net import open_unix_socket, serve_unix

def server():
    yield serve_unix(
        server_handle, 
        '/tmp/app.sock', 
        mode=0o600
    )

def client():
    stream = yield open_unix_socket(
        '/tmp/app.sock'
    )
    yield stream.send_all("message")

await syntax

from tonio.colored.net import open_unix_socket, serve_unix

async def server():
    await serve_unix(
        server_handle, 
        '/tmp/app.sock', 
        mode=0o600
    )

async def client():
    stream = await open_unix_socket(
        '/tmp/app.sock'
    )
    await stream.send_all("message")

TLS streams

TonIO implement TLS wrappers around the streaming APIs through primitives in the tonio.net.tls module.

TonIO provides the TLSStream and TLSListener object wrappers and the following high-level helpers:

  • open_tls_over_tcp_stream: a coroutine to open a TLSStream wrapping a TCP SocketStream
  • open_tls_over_tcp_listeners: a coroutine to initialise TLSListener objects
  • serve_tls_over_tcp: a coroutine that joins open_tls_over_tcp_listeners and serve_listeners in one call

Low-level sockets

The tonio.net.socket module provides TonIO's basic low-level networking API.
Generally, the API exposed by this module mirrors the standard library socket module.

TonIO socket objects are overall very similar to the standard library socket objects, with the main difference being that blocking methods become coroutines.

yield syntax

import tonio
from tonio.net import socket

def server():
    sock = socket.socket()
    with sock:
        yield sock.bind(('127.0.0.1', 8000))
        sock.listen()

        while True:
            client, _ = yield sock.accept()
            tonio.spawn(server_handle(client))

def server_handle(connection):
    with connection:
        # receive some data
        data = yield connection.recv(4096)

def client():
    sock = socket.socket()
    with sock:
        yield sock.connect(('127.0.0.1', 8000))
        yield sock.send("message")

await syntax

import tonio.colored as tonio
from tonio.colored.net import socket

async def server():
    sock = socket.socket()
    with sock:
        await sock.bind(('127.0.0.1', 8000))
        sock.listen()

        while True:
            client, _ = await sock.accept()
            tonio.spawn(server_handle(client))

async def server_handle(connection):
    with connection:
        # receive some data
        data = await connection.recv(4096)

async def client():
    sock = socket.socket()
    with sock:
        await sock.connect(('127.0.0.1', 8000))
        await sock.send("message")

Filesystem module

TonIO's fs module exposes async API for filesystem operations (that are run in the blocking thread-pool). It provides open, a Path class mirroring pathlib.Path, and wrap_file to adopt an already-open file object.

yield syntax

import tonio
import tonio.fs as fs

def main():
    f = yield fs.open('data.txt', 'w')
    yield f.write('hello')
    yield f.close()

    path = fs.Path('data.txt')
    if (yield path.exists()):
        print((yield path.read_text()))

    for entry in (yield fs.Path('.').iterdir()):
        print(entry.name)

await syntax

import tonio.colored as tonio
import tonio.colored.fs as fs

async def main():
    async with await fs.open('data.txt', 'w') as f:
        await f.write('hello')

    path = fs.Path('data.txt')
    if await path.exists():
        print(await path.read_text())

    for entry in await fs.Path('.').iterdir():
        print(entry.name)

Operations that touch the filesystem are asynchronous; everything else stays synchronous.

Note: methods returning several paths (iterdir, glob, rglob, walk) are resolved in a single hop and give back a list. Since walk is fully materialised, mutating its dirnames does not prune the traversal, unlike pathlib.Path.walk.

Reading a file line by line differs between the two flavours. The await syntax supports async for and async with, neither of which the yield syntax can express:

yield syntax

def read_lines(path):
    f = yield fs.open(path, 'r')
    try:
        while True:
            line = yield f.readline()
            if not line:
                break
            print(line)
    finally:
        yield f.close()

await syntax

async def read_lines(path):
    async with await fs.open(path, 'r') as f:
        async for line in f:
            print(line)

Subprocesses

TonIO exposes two coroutines to run child processes: run_process for the common "run it and collect the outcome" case, and open_process for interacting with a process while it runs. Both spawn the process on the blocking thread-pool.

run_process returns a subprocess.CompletedProcess and accepts:

  • stdin: bytes to feed to the child (defaults to b'', meaning "close stdin immediately"), or a file descriptor/subprocess constant
  • capture_stdout / capture_stderr: when true, the relevant stream is collected and available on the result
  • check: when true (the default), a non-zero exit code raises subprocess.CalledProcessError

Any other keyword argument is forwarded to subprocess.Popen.

yield syntax

import tonio

def main():
    result = yield tonio.run_process(
        ['echo', 'hello'],
        capture_stdout=True
    )
    print(result.returncode)
    print(result.stdout)

await syntax

import tonio.colored as tonio

async def main():
    result = await tonio.run_process(
        ['echo', 'hello'],
        capture_stdout=True
    )
    print(result.returncode)
    print(result.stdout)

open_process returns a Process object instead, giving access to the running child. Passing subprocess.PIPE for stdin, stdout or stderr exposes the corresponding pipe as a stream on the process object, implementing the same send_all and receive_some coroutines of network streams:

yield syntax

import subprocess
import tonio

def main():
    proc = yield tonio.open_process(
        ['cat'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    yield proc.stdin.send_all(b'hello')
    proc.stdin.close()
    data = yield proc.stdout.receive_some()
    code = yield proc.wait()

await syntax

import subprocess
import tonio.colored as tonio

async def main():
    proc = await tonio.open_process(
        ['cat'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    await proc.stdin.send_all(b'hello')
    proc.stdin.close()
    data = await proc.stdout.receive_some()
    code = await proc.wait()

The Process object exposes:

  • args and pid: the command and the process identifier
  • stdin, stdout, stderr: the piped streams, or None when not piped
  • stdio: a (stdin, stdout) tuple, when both are piped
  • returncode and poll(): the exit code, or None while the process is still running
  • wait: a coroutine waiting for the process to exit, returning its exit code
  • send_signal, terminate, kill: synchronous methods to signal the process

Note: unlike run_process, open_process does not reap the child for you: remember to wait on it — possibly after a kill — otherwise the child outlives your task.

Note: processes in TonIO only communicate over unbuffered byte streams: the universal_newlines, text, encoding, errors and bufsize options of subprocess are not supported.

Signals

TonIO provides a context manager to catch signals.

The usage of such context manager requires to first configure the runtime to listen for such signals:

yield syntax

import signal
import tonio
from tonio.time import interval

def sig_handle():
    with tonio.signal_receiver(
        signal.SIGHUP, 
        signal.SIGUSR1
    ) as sigs:
        for ev in sigs:
            sig = yield ev
            if sig == signal.SIGHUP:
                ...

@tonio.main(
    signals=[signal.SIGHUP, signal.SIGUSR1]
)
def main():
    tonio.spawn(sig_handle())
    ticker = interval(1)
    while True:
        yield ticker.tick()

await syntax

import signal
import tonio.colored as tonio
from tonio.colored.time import interval

async def sig_handle():
    with tonio.signal_receiver(
        signal.SIGHUP, 
        signal.SIGUSR1
    ) as sigs:
        async for sig in sigs:
            if sig == signal.SIGHUP:
                ...

@tonio.main(
    signals=[signal.SIGHUP, signal.SIGUSR1]
)
async def main():
    tonio.spawn(sig_handle())
    ticker = interval(1)
    while True:
        await ticker.tick()

Libraries built on TonIO

In addition to the patches provided by the TonIO-Monkey project, the following libraries target TonIO natively:

License

TonIO is released under the BSD License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tonio-0.9.5.tar.gz (89.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tonio-0.9.5-cp315-cp315t-musllinux_1_1_x86_64.whl (635.4 kB view details)

Uploaded CPython 3.15tmusllinux: musl 1.1+ x86-64

tonio-0.9.5-cp315-cp315t-musllinux_1_1_armv7l.whl (694.2 kB view details)

Uploaded CPython 3.15tmusllinux: musl 1.1+ ARMv7l

tonio-0.9.5-cp315-cp315t-musllinux_1_1_aarch64.whl (585.2 kB view details)

Uploaded CPython 3.15tmusllinux: musl 1.1+ ARM64

tonio-0.9.5-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (421.8 kB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.17+ x86-64

tonio-0.9.5-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (417.6 kB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.17+ ARMv7l

tonio-0.9.5-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (406.9 kB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.17+ ARM64

tonio-0.9.5-cp315-cp315t-manylinux_2_12_i686.manylinux2010_i686.whl (444.8 kB view details)

Uploaded CPython 3.15tmanylinux: glibc 2.12+ i686

tonio-0.9.5-cp315-cp315t-macosx_11_0_arm64.whl (364.2 kB view details)

Uploaded CPython 3.15tmacOS 11.0+ ARM64

tonio-0.9.5-cp315-cp315t-macosx_10_12_x86_64.whl (384.6 kB view details)

Uploaded CPython 3.15tmacOS 10.12+ x86-64

tonio-0.9.5-cp314-cp314t-musllinux_1_1_x86_64.whl (635.6 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.1+ x86-64

tonio-0.9.5-cp314-cp314t-musllinux_1_1_armv7l.whl (694.0 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.1+ ARMv7l

tonio-0.9.5-cp314-cp314t-musllinux_1_1_aarch64.whl (585.4 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.1+ ARM64

tonio-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (421.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

tonio-0.9.5-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (417.5 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARMv7l

tonio-0.9.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (407.0 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

tonio-0.9.5-cp314-cp314t-manylinux_2_12_i686.manylinux2010_i686.whl (444.7 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.12+ i686

tonio-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl (364.3 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

tonio-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl (384.7 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

File details

Details for the file tonio-0.9.5.tar.gz.

File metadata

  • Download URL: tonio-0.9.5.tar.gz
  • Upload date:
  • Size: 89.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tonio-0.9.5.tar.gz
Algorithm Hash digest
SHA256 91cc51966cc4a413090900338dd571953b379002dad83f8b7c382f0d0896db02
MD5 39bb2a6f464a9affee5afa17695cb271
BLAKE2b-256 098356828461b7c612c58136c406ee18dfb650c674cd49f4222151cdc569d806

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5.tar.gz:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 c5448364986a89aa3877aa70b0bbfa40975dd7d767f2a71f1567f95e8098fed4
MD5 19a2a09f00168b42dc84c949c9a67ab9
BLAKE2b-256 140e70256702618df30422854017de1589ed90fe2d03875d05abf8c05ab73932

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-musllinux_1_1_x86_64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-musllinux_1_1_armv7l.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-musllinux_1_1_armv7l.whl
Algorithm Hash digest
SHA256 b1e3f9ecc721ae82ef473e2be38d4f26f4a8230d2561ccb88943b45d06c60e43
MD5 8504ab6db5a1dc3f142a299b3e258a5b
BLAKE2b-256 9f6ea47bc8004ab929667814e50b28a4ce59881f68444b08f9f125dda9f60eae

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-musllinux_1_1_armv7l.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 44bf27cb937945fd9881d874e0c1fce2fad0b90da7c569a7be7c2d6d364265bf
MD5 5e81267503b7c38ac7548401199ec5fb
BLAKE2b-256 c65b7d32c09c978a91a30c510892dfc009d0bd39d306a21dd9c4035668e3b3f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-musllinux_1_1_aarch64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2fd00657f55e2469cdecdbb8805458304ce2931febe3b97184a1236f716b9261
MD5 9dc6097569b5d66bedb8a2d94360bc20
BLAKE2b-256 86e2da82164a80d10d6b00a447e46082d4d29b1065f1e99b0a65a54098f672fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 302255937d1defc54b331b08875fa4d8fe18d28fb8dd702c639b1719a14358e6
MD5 56eda25480a11812e485046da64a6dc8
BLAKE2b-256 31188136ad5dcfdd7bb8b686e5f4e77f3eec8b0b2f1ec2df1ba29b8ebdd68fd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9802abe89eec9f73ffa3d0f43e8e55aaf60c762ae9bee8ea8f4d12b6c92d5601
MD5 de8986bd7bf48f65028b635f1c211020
BLAKE2b-256 175c10e727e82af8faea45c38c994f19f089971ee93ba4f8b63ec3c0a32ff023

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 9687298ef6cd07f9552c28e667e4706a65d1cd3fe09d8052f857536999681d5a
MD5 b40d6b7a0f684ed34e6bfaae19def08c
BLAKE2b-256 0abaef29e292928ee529ee115037dcf19615db1c3721a745752bb6b98b084c88

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-manylinux_2_12_i686.manylinux2010_i686.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d9009140734610386f21d11f4eed2b5d71ac5c04b0340293aa916536dcee184a
MD5 a94117a3b99b1c7f87a53abce496b147
BLAKE2b-256 f11a8f19144824308cabbdb9f86c0d6e4830e39847801346c0b9ec4d0fcb6be9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-macosx_11_0_arm64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp315-cp315t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp315-cp315t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 42199412f05e6b3cfa2bc25c7a8e2e413e1c7a71506badecc13632ce0d679bcc
MD5 20e719ea233a4441ddcf499e5416bdea
BLAKE2b-256 6ea5dec9abf6b4c7f2203de7559ae2affb98453eee391cdb26bf9221defe4577

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp315-cp315t-macosx_10_12_x86_64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 778664aa4dcac24bc7b1b6d3a95b02b2718d581ec74f87afb232a59cf9be2332
MD5 40cf59c3f9d18a39c9e03d89cca4a7ba
BLAKE2b-256 bdc3210aa499d9c7798be9910cb3c96a512dacd5df9b32e3d103003f27eb5dd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-musllinux_1_1_x86_64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-musllinux_1_1_armv7l.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-musllinux_1_1_armv7l.whl
Algorithm Hash digest
SHA256 c7e8f21f7ed82f76c61efcb92b0a4fed730220c82b925e1c6ce02a28fbd7ae88
MD5 cf80f1e829f32d87f0414262ee4713d4
BLAKE2b-256 ebfda26d8c2ffcdcd34992601214c15af2cc3894dce0e7280e5b0111b4b7f05d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-musllinux_1_1_armv7l.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 92f5b773d86f26d8acec161035623cb59006c444c71b929b6b960bde67f6890f
MD5 de7fe5fcfb9b01e954084a99d182c4f6
BLAKE2b-256 31517b120dbbe3bc16fbc852052c91cd86163ae26e8094652d9953f321ecb304

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-musllinux_1_1_aarch64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9fa204763f9d563d1e408f273940c7c8f51c971d21dd928a0b4d6090b8cb440f
MD5 fcb81b6a343e2770b4a4f3f149c5ba7d
BLAKE2b-256 598abf74e4d5ab6ad4962feb10849904441dc55497867941690f5d227343aae3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 460d81ab49c454d7a4472698891a120d0576d8602bdbc2b20e58d0d2756c6ee7
MD5 2f0dea2049a354589ba7731cd7debdf8
BLAKE2b-256 4f415f64cd1c3229ffc096c36e3f05c14c11fdd7139da21c5a052674e14399a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9ec5c1ff52915cbf5c12cc632379e54deacd61e578fdb19ec2a2eafb3bfecfee
MD5 6cc5967e265bbfde26d64963654bfd3a
BLAKE2b-256 5c7cd9edd34faa051b0ae82d7b5ebbcc27e471dedfd164d9254271c6237a3438

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 fa6e92b65184b9bba740ccea3cc8af9d3a2c1d730b82503f413fd0ff19d432d1
MD5 d32aa4053a7c3d9094a317a530b1c4ff
BLAKE2b-256 6ab7e3cf9b54e6eeee317d2cb8bc17483312b45159c918fdf14d2385e68b13e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-manylinux_2_12_i686.manylinux2010_i686.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 821c28e7d423b8ef2118e77865518f8635e1c16915e2b17d5e89ed426a4f387a
MD5 dc5f84ee366c97ca4b4e4158c47d15ac
BLAKE2b-256 5751651fc65f8b9c604172d53f77abad7994b9f28367013d2bcaad63a6c08ca6

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tonio-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tonio-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 df9fe52f9951a408de1db9cc9830d685ecd65ce1caf23dc951b23807b9147982
MD5 21fd399b9e4f9e93cd2d15f1a4f69ca5
BLAKE2b-256 26c2e14040b67a7ad5d48fab5821ab02d79b70aca6a2650feadb0ad7637bf47f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tonio-0.9.5-cp314-cp314t-macosx_10_12_x86_64.whl:

Publisher: release.yml on gi0baro/tonio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page