Interprocess communication (IPC) Second way: pipe (not recommended, you can understand), can cause data unsafe situation, we will talk later Why bring data insecurity problems.
# Coding: UTF-8
from multiprocessing Import Process, Pipe
DEF FUNC (conn2):
conn2.send ( " I am a child process. " )
Print ( " message from the parent process: " , conn2.recv ())
conn2.close ()
IF the __name__ == ' __main__ ' :
, conn1,, conn2 = pipe () # create a channel to get the pipe ends, duplex communication mode, both sides can send and receive messages
p = Process (target = func, args = ( conn2,)) # Plug one end of the pipe to the child process
p.start () # open a child process
Print ( "Message from the child process: " , conn1.recv ()) # primary process to accept messages from the child process
conn1.send ( " I am the Lord process. " ) # Primary process to send a message to the child
conn1.close ()
# from news of the child process: I was the child.
# messages from the parent process: I am the Lord process.