Are*_*ski 6 file-io file system-calls python-3.x
如何在Python 3中调用readahead系统调用?
readahead()在文件上启动readahead,以便从缓存中满足从该文件的后续读取,而不是在磁盘I/O上阻塞
从以下位置使用ctypes并拉入系统调用libc:
import ctypes, os
# load ourselves, we already have libc
libc = ctypes.CDLL(None, use_errno=True)
# XXX - YMMV, ctypes doesn't have c_off_t much less c_off64_t.
# Assume it's c_longlong, but don't count on that.
off64_t = ctypes.c_longlong
def readahead(fobj, offset, count):
fno = fobj if isinstance(fobj, int) else fobj.fileno()
code = libc.readahead(
ctypes.c_int(fno),
off64_t(offset),
ctypes.c_size_t(count)
)
if code != 0:
errno = ctypes.get_errno()
raise OSError(errno, os.strerror(errno))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
227 次 |
| 最近记录: |