Python 3.7+Linuxosfunction
os.preadv
os — positional I/O
Like pread, but scatters into multiple buffers at an offset. Availability: Linux.
Syntax
os.preadv(...)
It combines pread and readv: reads from a given offset into several buffers in one system call. Buffers fill in order, and the last may stay partly empty — check the returned byte count. It supports flags such as RWF_NOWAIT; it is a low-level tool for servers and databases rather than everyday tasks.
Examples
import os
fd = os.open('preadv-demo.bin', os.O_RDWR | os.O_CREAT | os.O_TRUNC) # временный файл для опытов
print(os.pwrite(fd, b'HEADERBODY', 0)) # → 10 — подготовили данные, позиция fd осталась в начале
bufs = [bytearray(6), bytearray(4)] # scatter-чтение: заголовок и тело в разные буферы
print(os.preadv(fd, bufs, 0), bytes(bufs[0]), bytes(bufs[1])) # → ? только Unix: 10 b'HEADER' b'BODY'
print(os.lseek(fd, 0, os.SEEK_CUR)) # → 0 — ни pwrite, ни preadv не сдвинули позицию fd (в отличие от os.readv)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy