进程的同步
# 进程的同步 (类似于线程的同步锁,同一时刻只能一个进程运行) from multiprocessing import Process, Lock import time def f(l, i): with l: time.sleep(1) print('helloworld %s' % i) # 上面with l: 相当于 # l.acquire() # print('helloworld %s' % i) # l.release() if __name__ == '__main__': lock = Lock() for num in range(10): Process(target=f, args=(lock, num,)).start()