Python multiprocessing manager class object thread/process safe -
i have following class shared between multiple consumers (using producer/consumer methodology). question involves methods called on class. need implement locks or manager class thread safe?
import multiprocessing mp multiprocessing.manager import basemanager class sampleclass(object): def __init__(self): self._count = 0 # locking need implemented here? def increment(self): self._count += 1 basemanager.register('sampleclass', sampleclass) manager = basemanager() manager.start() instance = manager.sampleclass() jobs = [] in range(0, 5): p = mp.process(target=some_func, args=(instance,)) jobs.append(p) p.start() p in jobs: p.join()
Comments
Post a Comment