Skip to content
Python aio bindings
Python C
Find file
Pull request Compare This branch is 2 commits ahead, 11 commits behind master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
pyaio
tests
AUTHORS
MANIFEST
README.markdown
setup.py

README.markdown

Python Asynchronous I/O bindings (aio.h)

Version 0.3 Linux only

You should wait for the callback to finish before queuing more requests in a tight loop. Or pyaio could hang against python pending queue length

Reading

API

python view = aio_read(fileno, file-offset, length, callback)

Example

import pyaio
import os

def aio_callback(buf, rcode, errno):
    if rcode > 0:
        print 'python callback %s' % buf
    elif rcode == 0:
        print "EOF"
    else:
        print "Error: %d" % errno

fd = os.open('/tmp/pyaio.txt', os.O_RDONLY)
pyaio.aio_read(fd, 10, 20, aio_callback)

Writing

API

python aio_write(fileno, buffer-object, file-offset, callback)

Example

import pyaio
import os

def aio_callback(rt, errno):
    if rt > 0:
        print "Wrote %d bytes" % rt
    else:
        print "Got error: %d" % errno

fd = os.open('/tmp/pyaio.txt', os.O_WRONLY)
pyaio.aio_write(fd, "Writing Test.......", 30, aio_callback)

gevent Wrapper

For a file() like wrapper around aio_read and aio_write using gevent a 'buffer' keyword argument to aioFile controls its internal buffer size

from pyaio.gevent import aioFile
with aioFile('/tmp/pyaio.txt') as fr:
    data = fr.read()  # Entire File

with aioFile('/tmp/pyaio.txt', 'w') as fw:
    fw.write(data)
Something went wrong with that request. Please try again.