from concurrent.futures.process import ProcessPoolExecutor from multiprocessing import Manager
def proc(d, l): if l.acquire(): d["t"] = d["t"] + 1 print(d["t"]) l.release() if __name__ == '__main__': d = Manager().dict() l = Manager().Lock() d["t"] = 1 process_pools = ProcessPoolExecutor(max_workers=4) for i in range(200): process_pools.submit(proc, d, l)
from concurrent.futures.process import ProcessPoolExecutor from multiprocessing import Manager
class T: def __init__(self): self.t = 1
def proc(self): self.t = self.t + 1
def proc(t, l): if l.acquire(): t["t"].proc() print(t["t"].t) l.release() if __name__ == '__main__': d = Manager().dict() l = Manager().Lock() d["t"] = T() process_pools = ProcessPoolExecutor(max_workers=4) for i in range(200): process_pools.submit(proc, d, l)