all Python 3Linux · macOSosfunction
os.mkfifo
os — special files
Create a named pipe (FIFO). Availability: Unix.
Syntax
os.mkfifo(...)
A named pipe looks like a file but stores no data on disk: opening it for reading blocks until someone opens it for writing, and vice versa. So in one thread you cannot open a FIFO for reading and then for writing — the first open() hangs; on Linux os.open() with O_RDWR works around it, but POSIX leaves that behaviour undefined. Permissions pass through the umask, as with mkdir.
Examples
import os, stat
os.mkfifo('demo.fifo') # → ? только Unix: в файловой системе появился именованный канал demo.fifo
print(stat.S_ISFIFO(os.stat('demo.fifo').st_mode)) # → True — это FIFO, а не обычный файл
os.mkfifo('private.fifo', 0o600) # → ? только Unix: канал, доступный на чтение и запись только владельцу
fd = os.open('demo.fifo', os.O_RDONLY | os.O_NONBLOCK) # → ? только Unix: обычный open() на чтение ждал бы, пока другой процесс не откроет канал на запись
os.mkfifo('demo.fifo') # → FileExistsError: [Errno 17] File exists: 'demo.fifo'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy