跳转到主要内容

适用于Linux、MacOS或Windows的异步文件I/O。

项目描述

Python包装器用于AIO

注意: 本地Linux aio实现自4.18内核版本起支持。

Linux AIO API的Python绑定和简单的asyncio包装器。

示例

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())

故障排除

linux 实现在现代Linux内核版本和文件系统中工作正常。因此,您可能遇到特定于您环境的问题。这不是错误,可能可以通过一些方法解决

  1. 升级内核
  2. 使用兼容的文件系统
  3. 使用基于线程或纯Python的实现。

自0.7.0版本以来,caio包含了一些实现此功能的方法。

  1. 在运行时,使用环境变量 CAIO_IMPL 并具有可能的值
    • linux - 使用本机Linux内核aio机制
    • thread - 使用C编写的基于线程的实现
    • python - 使用纯Python实现
  2. 文件 default_implementation 位于caio安装路径中的 __init__.py 附近。这对于发行版包维护者很有用。此文件可能包含注释(以 # 符号开始的行)和第一行应该是 linuxthreadpython 之一。

旧版本允许直接导入目标实现。

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

caio-0.9.17.tar.gz (25.0 kB 查看哈希值)

上传时间

构建分布

caio-0.9.17-py3-none-any.whl (19.1 kB 查看哈希值)

上传时间 Python 3

caio-0.9.17-cp312-cp312-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.7 kB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

caio-0.9.17-cp312-cp312-macosx_10_9_universal2.whl (37.9 kB 查看哈希值)

上传时间 CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

caio-0.9.17-cp311-cp311-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (80.0 kB 查看哈希值)

上传时间 CPython 3.11 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

caio-0.9.17-cp311-cp311-macosx_10_9_universal2.whl (37.8 kB 查看哈希值)

上传时间 CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

caio-0.9.17-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (79.4 kB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

caio-0.9.17-cp310-cp310-macosx_10_9_universal2.whl (37.8 kB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

caio-0.9.17-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (78.7 kB 查看哈希值)

上传于 CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

caio-0.9.17-cp39-cp39-macosx_10_9_universal2.whl (37.9 kB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

caio-0.9.17-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (79.8 kB 查看哈希值)

上传于 CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

caio-0.9.17-cp38-cp38-macosx_11_0_universal2.whl (38.0 kB 查看哈希值)

上传于 CPython 3.8 macOS 11.0+ universal2 (ARM64, x86-64)

由以下提供支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面