https://github.com/fuyukai/century-ring
Century Ring
https://github.com/fuyukai/century-ring
Last synced: 5 months ago
JSON representation
Century Ring
- Host: GitHub
- URL: https://github.com/fuyukai/century-ring
- Owner: Fuyukai
- License: lgpl-3.0
- Created: 2024-10-05T23:17:00.000Z (9 months ago)
- Default Branch: mizuki
- Last Pushed: 2025-01-16T17:54:47.000Z (5 months ago)
- Last Synced: 2025-01-16T19:08:58.066Z (5 months ago)
- Language: Python
- Size: 83 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
Century Ring
============`Century Ring `_ is a Python binding to the Tokio
``io_uring`` library.Example
-------A basic example of writing to and reading from a temporary file. Obviously in the real world you
would want to have better error handling and simultaneous tasks, but this shows the basic flow of
how to use the uring... code-block:: python
import os
from century_ring import make_io_ring, raise_for_cqe
from century_ring.files import FileOpenFlag, FileOpenModewith make_io_ring() as ring:
ring.prep_openat(None, b"/tmp", FileOpenMode.READ_WRITE, flags={FileOpenFlag.TEMPORARY_FILE})
ring.submit_and_wait()
raw_cqe = ring.get_completion_entries()[0]
raise_for_cqe(raw_cqe)
open_fd = raw_cqe.resultring.prep_write(open_fd, b"wow!")
ring.submit_and_wait()
raise_for_cqe(ring.get_completion_entries()[0])ring.prep_read(open_fd, 4096, offset=0)
ring.submit_and_wait()
read_cqe = ring.get_completion_entries()[0]
raise_for_cqe(read_cqe)buffer = read_cqe.buffer
assert buffer is not None
assert buffer == b"wow!"
print(buffer)os.close(open_fd)