| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: caio |
| 3 |
Version: 0.9.24 |
| 4 |
Summary: Asynchronous file IO for Linux MacOS or Windows. |
| 5 |
Author-email: Dmitry Orlov <[email protected]> |
| 6 |
License-Expression: Apache-2.0 |
| 7 |
Project-URL: Source Code, https://github.com/mosquito/caio/ |
| 8 |
Classifier: Topic :: Software Development |
| 9 |
Classifier: Topic :: Software Development :: Libraries |
| 10 |
Classifier: Intended Audience :: Developers |
| 11 |
Classifier: Natural Language :: English |
| 12 |
Classifier: Operating System :: MacOS |
| 13 |
Classifier: Operating System :: POSIX |
| 14 |
Classifier: Operating System :: Microsoft |
| 15 |
Classifier: Programming Language :: Python |
| 16 |
Classifier: Programming Language :: Python :: 3 |
| 17 |
Classifier: Programming Language :: Python :: 3.9 |
| 18 |
Classifier: Programming Language :: Python :: 3.10 |
| 19 |
Classifier: Programming Language :: Python :: 3.11 |
| 20 |
Classifier: Programming Language :: Python :: 3.12 |
| 21 |
Classifier: Programming Language :: Python :: 3.13 |
| 22 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 23 |
Requires-Python: >=3.9 |
| 24 |
Description-Content-Type: text/markdown |
| 25 |
License-File: COPYING |
| 26 |
Provides-Extra: develop |
| 27 |
Requires-Dist: aiomisc-pytest; extra == "develop" |
| 28 |
Requires-Dist: coveralls; extra == "develop" |
| 29 |
Requires-Dist: pylama[toml]; extra == "develop" |
| 30 |
Requires-Dist: pytest; extra == "develop" |
| 31 |
Requires-Dist: pytest-cov; extra == "develop" |
| 32 |
Requires-Dist: setuptools; extra == "develop" |
| 33 |
Dynamic: license-file |
| 34 |
|
| 35 |
Python wrapper for AIO |
| 36 |
====================== |
| 37 |
|
| 38 |
> **NOTE:** Native Linux aio implementation supports since 4.18 kernel version. |
| 39 |
|
| 40 |
Python bindings for Linux AIO API and simple asyncio wrapper. |
| 41 |
|
| 42 |
Example |
| 43 |
------- |
| 44 |
|
| 45 |
```python |
| 46 |
|
| 47 |
import asyncio |
| 48 |
from caio import AsyncioContext |
| 49 |
|
| 50 |
loop = asyncio.get_event_loop() |
| 51 |
|
| 52 |
async def main(): |
| 53 |
# max_requests=128 by default |
| 54 |
ctx = AsyncioContext(max_requests=128) |
| 55 |
|
| 56 |
with open("test.file", "wb+") as fp: |
| 57 |
fd = fp.fileno() |
| 58 |
|
| 59 |
# Execute one write operation |
| 60 |
await ctx.write(b"Hello world", fd, offset=0) |
| 61 |
|
| 62 |
# Execute one read operation |
| 63 |
print(await ctx.read(32, fd, offset=0)) |
| 64 |
|
| 65 |
# Execute one fdsync operation |
| 66 |
await ctx.fdsync(fd) |
| 67 |
|
| 68 |
op1 = ctx.write(b"Hello from ", fd, offset=0) |
| 69 |
op2 = ctx.write(b"async world", fd, offset=11) |
| 70 |
|
| 71 |
await asyncio.gather(op1, op2) |
| 72 |
|
| 73 |
print(await ctx.read(32, fd, offset=0)) |
| 74 |
# Hello from async world |
| 75 |
|
| 76 |
|
| 77 |
loop.run_until_complete(main()) |
| 78 |
``` |
| 79 |
|
| 80 |
Troubleshooting |
| 81 |
--------------- |
| 82 |
|
| 83 |
The `linux` implementation works normal for modern linux kernel versions |
| 84 |
and file systems. So you may have problems specific for your environment. |
| 85 |
It's not a bug and might be resolved some ways: |
| 86 |
|
| 87 |
1. Upgrade the kernel |
| 88 |
2. Use compatible file system |
| 89 |
3. Use threads based or pure python implementation. |
| 90 |
|
| 91 |
The caio since version 0.7.0 contains some ways to do this. |
| 92 |
|
| 93 |
1. In runtime use the environment variable `CAIO_IMPL` with possible values: |
| 94 |
* `linux` - use native linux kernels aio mechanism |
| 95 |
* `thread` - use thread based implementation written in C |
| 96 |
* `python` - use pure python implementation |
| 97 |
2. File ``default_implementation`` located near ``__init__.py`` in caio |
| 98 |
installation path. It's useful for distros package maintainers. This file |
| 99 |
might contains comments (lines starts with ``#`` symbol) and the first line |
| 100 |
should be one of ``linux`` ``thread`` or ``python``. |
| 101 |
|
| 102 |
Previous versions allows direct import of the target implementation. |