Skip to main content

Asynchronous file IO for Linux Posix and Windows.

Project description

Python bindings for Linux AIO API and simple asyncio wrapper.

Example

import asyncio
from caio import AsyncioContext

loop = asyncio.get_event_loop()

async def main():
    # max_requests=128 by default
    ctx = AsyncioContext(max_requests=128)

    with open("test.file", "wb+") as fp:
        fd = fp.fileno()

        # Execute one write operation
        await ctx.write(b"Hello world", fd, offset=0)

        # Execute one read operation
        print(await ctx.read(32, fd, offset=0))

        # Execute one fdsync operation
        await ctx.fdsync(fd)

        op1 = ctx.write(b"Hello from ", fd, offset=0)
        op2 = ctx.write(b"async world", fd, offset=11)

        await asyncio.gather(op1, op2)

        print(await ctx.read(32, fd, offset=0))
        # Hello from async world


loop.run_until_complete(main())

Troubleshooting

The linux implementation works normal for modern linux kernel versions and file systems. So you may have problems specific for your environment. It’s not a bug and might be resolved some ways:

  1. Upgrade the kernel

  2. Use compatible file system

  3. Use threads based or pure python implementation.

The caio since version 0.7.0 contains some ways to do this.

1. In runtime use the environment variable CAIO_IMPL with possible values:

  • linux - use native linux kernels aio mechanism

  • thread - use thread based implementation written in C

  • python - use pure python implementation

2. File default_implementation located near __init__.py in caio installation path. It’s useful for distros package maintainers. This file might contains comments (lines starts with # symbol) and the first line should be one of linux thread or python.

Previous versions allows direct import of the target implementation.

Project details


Download files

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

Source Distribution

caio-0.9.1.tar.gz (24.0 kB view hashes)

Uploaded Source

Built Distributions

caio-0.9.1-py3-none-any.whl (18.4 kB view hashes)

Uploaded Python 3

caio-0.9.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (84.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

caio-0.9.1-cp39-cp39-macosx_10_14_x86_64.whl (29.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

caio-0.9.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (85.2 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

caio-0.9.1-cp38-cp38-macosx_10_14_x86_64.whl (29.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

caio-0.9.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (84.9 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

caio-0.9.1-cp37-cp37m-macosx_10_14_x86_64.whl (29.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

caio-0.9.1-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (83.1 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

caio-0.9.1-cp36-cp36m-macosx_10_14_x86_64.whl (29.7 kB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page