这是一个围绕liburingc库的Python+CFFI包装器,它是安装和拆卸实例的助手。
liburing的Python项目详细描述
这是一个围绕liburingc库的Python+CFFI包装器,它是设置和删除io_uring实例的助手。在
阅读如何使用Liburing(pdf)
另一个好的文档Lord of the io_uring
需要
- Linux 5.5+ (5.7+ recommended)
- Python 3.6+
包括
- liburing 0.7.0
安装、更新和卸载(Alpha)
{a3}使用Python包装器安装^;升级:
pip install liburing pip install --upgrade liburing pip uninstall liburing
直接从GitHub安装:
^{pr2}$要了解所有函数和定义:
import liburing help(liburing)
简单文件示例
importosimportos.pathfromliburingimport*defopen(ring,cqes,path,flags,mode=0o660,dir_fd=-1):# file path must be absolute path and in bytes._path=os.path.abspath(path).encode()sqe=io_uring_get_sqe(ring)# sqe(submission queue entry)io_uring_prep_openat(sqe,dir_fd,_path,flags,mode)return_submit_and_wait(ring,cqes)# returns fddefwrite(ring,cqes,fd,data,offset=0):buffer=bytearray(data)iov=iovec(buffer)sqe=io_uring_get_sqe(ring)io_uring_prep_write(sqe,fd,iov[0].iov_base,iov[0].iov_len,offset)return_submit_and_wait(ring,cqes)# returns length(s) of bytes writtendefread(ring,cqes,fd,length,offset=0):buffer=bytearray(length)iov=iovec(buffer)sqe=io_uring_get_sqe(ring)io_uring_prep_read(sqe,fd,iov[0].iov_base,iov[0].iov_len,offset)read_length=_submit_and_wait(ring,cqes)# get actual length of file read.returnbuffer[:read_length]defclose(ring,cqes,fd):sqe=io_uring_get_sqe(ring)io_uring_prep_close(sqe,fd)_submit_and_wait(ring,cqes)# no error means success!def_submit_and_wait(ring,cqes):io_uring_submit(ring)# submit entryio_uring_wait_cqe(ring,cqes)# wait for entry to finishcqe=cqes[0]# cqe(completion queue entry)result=trap_error(cqe.res)# auto raise appropriate exception if failed# note `cqe.res` returns results, if ``< 0`` its an error, if ``>= 0`` its the value# done with current entry so clear it from completion queue.io_uring_cqe_seen(ring,cqe)returnresult# type: intdefmain():ring=io_uring()cqes=io_uring_cqes()try:io_uring_queue_init(8,ring,0)fd=open(ring,cqes,'/tmp/liburing-test-file.txt',os.O_CREAT|os.O_RDWR)print('fd:',fd)length=write(ring,cqes,fd,b'hello world')print('wrote:',length)content=read(ring,cqes,fd,length)print('read:',content)close(ring,cqes,fd)print('closed.')finally:io_uring_queue_exit(ring)if__name__=='__main__':main()
许可证
免费,公共领域(CC0)。Read more
托多
- create more test
- Development Status :: 4 - Beta
- create example
- Development Status :: 5 - Production/Stable
- 项目
标签: