The method of process or other properties of the object

#join方法
import time, os
from multiprocessing import Process
def task(name, n):
print('%s is running'%name)
time.sleep(n)
if __name__ =='__main__':
start = time.time()
p1 = Process(target=task, args=('子进程1',5))
p2 = Process(target=task, args=('子进程2',3))
p3 = Process(target=task, args=('子进程3',2))
p1.start()
p2.start()
p3.start()
p1.join() The method of this write time is not # cumulative time (serial)
p2.join ()
p3.join ()
Print ( 'primary' , the time.time () - Start)
Print (p1.pid)
Print (p2.pid)
Print (p3.pid)



Import Time , OS
from multiprocessing Import Process
DEF Task (name , n-):
Print ( '% S running IS' name%)
the time.sleep (n-)
IF the __name__ == '__main__':
Start Time =. Time ()
P1 = process ( target = Task , args = ( 'sub-process. 1' , . 5))
P2 = process ( target = Task , args = ( 'sub-process 2' , . 3))
P3 = process (= Task target , args = ( 'sub-process 3' , 2))
p1.start () # This method will write the cumulative time (serial)
p1.join ()
p2.start ()
p2.join ()
p3.start ()
p3.join ()
Print ( 'primary' , the time.time () - Start)
Print (p1.pid)
Print (p2.pid)
Print (p3.pid)



Import Time , OS
from multiprocessing Import Process
DEF Task ( name , n-):
Print ( '% S running IS' name%)
the time.sleep (n-)
IF the __name__ == '__main__':
Start the time.time = ()
P1 = Process ( target = Task , args = ( 'sub process 1 ', . 5))
P2 = Process ( target = Task , args = ( 'sub-process 2' , . 3))
P3 = Process ( target = Task , args = ( 'sub-process. 3' , 2))
P_L = [P1 , P2 , P3]
for P in P_L:
p.start ()
for P in P_L:
p.join ()
Print ( 'primary' , the time.time () - Start)
Print (p1.pid)
Print (p2.pid)
Print (p3.pid)
# is_alive understand the process of determining whether the survival of
Import Time , os
from multiprocessing Import process
DEF Task (name):
Print ( '% S IS running'% name)
time.sleep(3)
if __name__ =='__main__':
start = time.time()
p1 = Process(target=task, args=('子进程1',))
p1.start() #此方法写会累计时间(串行)
print(p1.is_alive())
p1.join()
print('主', time.time() - start)
print(p1.pid)
print(p1.is_alive())


import time, os
from multiprocessing import Process
def task(name):
print('%s is running'%name)
time.sleep(3)
if __name__ =='__main__':
p = Process(target=task, name = 'My name is the process' , args = ( 'child process' ,))
p.start () # start the process (just send a command to the operating system is not executed successfully)
p.join () # Wait for the process to perform successfully
p.terminate () # kill process Print (p.is_alive ()) # determine whether the process alive Print (p.name) # view the process name




Guess you like

Origin www.cnblogs.com/yuexijun/p/11515314.html