Python 3.3+Linux · macOSosfunction
os.writev
os — positional I/O
Write to a descriptor from multiple buffers (gather write). Availability: Unix.
Syntax
os.writev(...)
It writes several bytes-like objects in one system call — no b''.join beforehand and no separate writes. That cuts kernel round-trips when sending a header and a body. It may write only part of the data, and the rest, possibly from the middle of one buffer, must then be written by you.
Examples
import os
fd = os.open('writev-demo.txt', os.O_RDWR | os.O_CREAT | os.O_TRUNC) # временный файл для опытов
print(os.writev(fd, [b'name;', b'age\n'])) # → 9 — обе части записаны одним системным вызовом
print(os.writev(fd, [b'Ann;', b'20\n'])) # → 7 — writev пишет с текущей позиции, дописывая в конец
print(os.pread(fd, 16, 0)) # → b'name;age\nAnn;20\n'
print(os.writev(fd, [])) # → 0 — пустой список буферов ничего не пишет
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy