Python provides four mechanisms for interprocess communication (IPC): anonymous pipes, named pipes, and sockets) and semaphores (signals ).
Pipeline (pipes) is a cross-regionProgramIs implemented by the operating system. An MPs queue is a one-way channel similar to the shared memory. It provides an interface for collecting simple files at both ends of the MPs queue. Generally, one program writes data to one end of the pipeline, and the other program reads data from the other end of the pipeline. A program can only see the end of its own pipeline and process the data like a common Python file.
The anonymous pipeline (anonymous pipes) usually works with the fork method of the process to associate the parent process with the child process through the shared pipeline file descriptor. The anonymous pipeline also applies to threads. The pipe method of the OS module generates an anonymous pipeline.
The named pipe (Named Pipes) corresponds to the file system of the operating system, represented by a file in the computer. The named pipeline is also called the operating OS. Processes that communicate through a named pipeline can be independent of each other. Operating system. mkfifo to create a named pipe is actually to create an external file, so you need to specify a file path.
Sockets (sockets) is a more common IPC Mechanism than pipelines. Sockets allow different programs on the same computer to transmit data to each other, and allow communications between programs on different computers in the network. When the socket acts as the IPC Mechanism on the same machine, the program connects to the socket through the global port of the machine. When a socket is used for network connection, the program must provide the machine name and port number. The socket module in Python provides socket-related methods, such as bind, listen, accept, Recv, and send.
Semaphores (signals) allow programs to send simple notification events to other programs and trigger corresponding actions. Python provides the signal module to register Python functions as handlers for specific signals.
Python provides the multiprocessing module for sub-process generation and multi-process communication. This module provides process-like process, lock-like lock, IPC tool pipe (anonymous pipeline), shared memory (Value and array), and queue.