First, two ways to open the process
Way One:
From multiprocessing import Process
Import time
def task (name):
Print ('%s is running '%name)
Time.sleep (3)
Print ('%s is do '%name)
# on Windows systems, the operation to turn on a subprocess must be placed in the sub-code of the If __name__ = = ' __main__ '
if __name__ = = ' __main__ ':
P=process (target=task,args= (' Egon ',)) #Process (target=task,kwargs={' name ': ' Egon '})
P.start () # just sends a signal to the operating system to turn on the sub-process
Print (' master ')
Way two:
From multiprocessing import Process
Import time
Class Myprocess (Process):
def __init__ (self,name):
Super (). __INIT__ ()
Self.name=name
def run (self):
Print ('%s is running '%self.name)
Time.sleep (3)
Print ('%s is do '%self.name)
# on Windows systems, the operation to turn on a subprocess must be placed in the sub-code of the If __name__ = = ' __main__ '
if __name__ = = ' __main__ ':
P=myprocess (' Egon ')
P.start () # just sends a signal to the operating system to turn on the sub-process
Print (' master ')
Second, join method
Let the main process wait in place, waiting for the child process to run, without affecting the execution of the child process
Third, Process object related properties
Process PID: Each process has a unique ID number within the operating system, called a PID
Iv. Zombie process and orphan process
Zombie Process: A process uses fork to create a child process, and if the child process exits, and the parent process does not call wait or waitpid to get state information for the child process, the process descriptor of the child process is still stored in the system. This process is called a zombie process.
Orphan process: One parent process exits, and one or more of its child processes are still running, then those child processes will become orphans. The orphan process will be adopted by the INIT process (process number 1) and the Init process completes the state collection for them.
Guardian Process: The essence is a ' child process ', the life cycle of the ' subprocess ' is <= by the life cycle of the daemon process
Six, mutual exclusion lock
Using the Mutex.acquire () method to realize the serial effect under concurrency
Python full stack day 34th------Two ways to open a process, join method, process object Other related properties and methods, zombie process, orphan process, daemon, mutex