我尝试通过 apply_async 将共享计数器传递给多处理中的任务,但它失败并出现这样的错误“RuntimeError:同步对象只能通过继承在进程之间共享”。这是怎么回事
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 = []