Python - Multiprocessing Error 'cannot start a process twice'
You get the assertion because you call start
on a single Process
object multiple times. Your example has an indentation error with that second process.append
and I'm assuming that the line shouldn't be there at all. Notice that the for loop where you start the processes is inside the upper for loop so it is executed for every process you create. On the second time through the loop, for example, you create the second process and then try to start the first process again. Just move the start code out of the upper for loop.
processes = []
for j in range(k-1):
processes.append(Process(target=sim, args=(int(j * d), int((j+1) * d), txt, pat, filename, patname, R, )))
for pr in processes:
pr.start()
for pr in processes:
pr.join()
while not R.empty():
print (R.get())