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