Multi-process considerations

# Note! Can not be shared between multiple processes memory, as in the following code n, n If you call in each sub-process, will be given! 
from multiprocessing Import Process
 Import Time
 Import Random


def func(i):
    print(i)
    
    
if __name__=='__main__':
    l=[]
    n- = 100 
    addr = [ ' A ' , ' B ' , ' C ' , ' D ' ]
     # cycled on a plurality of sub-processes 
    for I in addr:
        p=Process(target=func,args=(i,))
        p.start()
        l.append(p)
    # Is best to use a list to join, to prevent some of the problems 
    [p.join () for the p- in L]
    the time.sleep ( . 1 )
     Print ( " selected from S to% " % (The random.choice (addr)))

 

Guess you like

Origin www.cnblogs.com/god-for-speed/p/11719083.html