PYTHON——多进程:进程间的同步

进程间的同步:

from multiprocessing import Process, Lock

def f(l, i):
    l.acquire()
    try:
        print('hello world', i)
    finally:
        l.release()

if __name__ == '__main__':
    lock = Lock()

    for num in range(10):
        Process(target=f, args=(lock, num)).start()

 

转载于:https://www.cnblogs.com/chenhaiming/p/9919409.html

你可能感兴趣的:(PYTHON——多进程:进程间的同步)