Python - How to use multiprocessing Lock in class instance?
问题 I am using Python 3.7 on Windows. What I am trying to do: - lock a method of an instance of a class, when another process has acquired that same lock. Attempts: I have already successfully done this, but I don't want a global variable here for the lock, but instead one completely internal to the class from multiprocessing import Lock, freeze_support,Pool from time import sleep def do_work(name): print(name+' waiting for lock to work...',end='') sleep(2) with lock: print('done!') print(name+'