Python 3.7+Linuxosfunction
os.pwritev
os — positional I/O
Like pwrite, but gathers from multiple buffers at an offset. Availability: Linux.
Syntax
os.pwritev(...)
It writes several buffers at a given offset in one system call without moving the shared position. It saves concatenating data into one bytes object first. Like other write functions it may write only part of the data. Flags such as RWF_DSYNC make the write synchronous without a separate fsync.
Examples
import os
fd = os.open('pwritev-demo.bin', os.O_RDWR | os.O_CREAT | os.O_TRUNC) # временный файл для опытов
parts = [b'HEADER', b'BODY'] # gather-запись: заголовок и тело лежат в разных буферах
print(os.pwritev(fd, parts, 0)) # → 10 — обе части ушли одним системным вызовом
print(os.pread(fd, 10, 0)) # → b'HEADERBODY' — буферы склеены подряд, без разделителей
print(os.lseek(fd, 0, os.SEEK_CUR)) # → 0 — pwritev пишет по смещению и не двигает позицию fd (в отличие от os.writev)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy