Python| os.mkfifo() 方法
Python中的OS 模块提供了与操作系统交互的功能。操作系统属于 Python 的标准实用程序模块。该模块提供了一种使用操作系统相关功能的可移植方式。
Python中的os.mkfifo()
方法用于创建具有指定模式的 FIFO(命名管道)命名路径。
FIFO是命名管道,可以像其他常规文件一样访问。此方法只创建FIFO但不打开它,并且创建的 FIFO 确实存在,直到它们被删除。 FIFO通常是我们作为客户端和“服务器类型进程”之间的集合点。
Syntax: os.mkfifo(path, mode = 0o666, *, dir_fd = None)
Parameters:
path: A path-like object representing the file system path. It can be a string or bytes object representing a file path.
mode (optional): A numeric value representing the mode of the FIFO (named pipe) to be created. The default value of mode parameter is 0o666 (octal).
dir_fd (optional): This is a file descriptor referring to a directory.
Note: The ‘*’ in parameter list indicates that all following parameters (Here in our case ‘dir_fd’) are keyword-only parameters and they can be provided using their name, not as a positional parameter.
Return type: This method does not return any value.
代码: os.mkfifo()
方法的使用
# Python3 program to explain os.mkfifo() method
# importing os module
import os
# Path
path = "./mypipe"
# Mode of the FIFO (a named pipe)
# to be created
mode = 0o600
# Create a FIFO named path
# with the specified mode
# using os.mkfifo() method
os.mkfifo(path, mode)
print("FIFO named '% s' is created successfully." % path)
FIFO named './mypipe' is created successfully.