I try to pass shared counter to tasks in multiprocessing by apply_async but it fails with such error "RuntimeError: Synchronized objects should only be shared between processes through inheritance". What's going on
def processLine(lines, counter, mutex):
pass
counter = multiprocessing.Value('i', 0)
mutex = multiprocessing.Lock()
pool = Pool(processes = 8)
lines = []
for line in inputStream:
lines.append(line)
if len(lines) >= 5000:
#don't queue more than 1'000'000 lines
while counter.value > 1000000:
time.sleep(0.05)
mutex.acquire()
counter.value += len(lines)
mutex.release()
pool.apply_async(processLine, args=(lines, counter, ), callback = collectResults)
lines = []