50 python use process

1 Raspberry Pi has four cores, but actually still use threads in a core. But the process can use to solve the problem.

 

A direct call method # 
Import Time 
Import Random 
from multiprocessing Import Process 

DEF RUN (name): 
    Print ( '% S Runing with' name%) 
    the time.sleep (random.randrange (l, 5)) 
    Print ( '% S running End' % name) 

P1 = Process (target = RUN, args = ( 'Anne',)) # must be added, number 
P2 = Process (target = RUN, args = ( 'Alice',)) 
P3 = Process (target = RUN, = args ( 'biantai',)) 
P4 = process (target = RUN, args = ( 'haha',)) 

p1.deamon = True # accompany the main process is closed and closed 
p2.deamon = True 
p3.deamon = True 
P4. = True deamon 
    
p1.start () 
p2.start () 
p3.start () 
p4.start () 

Print ( "main thread")

  

Guess you like

Origin www.cnblogs.com/kekeoutlook/p/12169376.html