这是一个围绕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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从提供的列表中获取非重复值   java为什么Thymeleaf从HashMap返回字符串?   java将矩阵推到窗口的中心   java如何包含webapp_配置。txt到播放的dist-zip?   java实现产品密钥   WebSphereJava。lang.UnsupportedClassVersionError:JVMCFRE003错误的主要版本;class=org/slf4j/impl/StaticLoggerBinder,偏移量=6   使用java创建动态树结构   java为什么JVM在一次繁忙的旋转暂停后,会对同一代码块显示更多的延迟?   java无法使用distrolessdebug访问jarfile docker   java JMeter如何将多行响应数据传递给ForEach控制器请求   java空指针异常碎片活动   java改变JFileChooser的外观   性能Java位集:高效地查找所有真实位?   java可扩展的recyclerview实现