I try to develop an algorithm using multiprocessing
package in Python, i learn some tutorial from internet and try to develop an algorithm with this package. After looking around and try my 'hello world' using Process
, Queue
and Pool
, i try to implement the Queue on this code
def main(queue):d = ...k = ...filename, patname, txt, pat = ...R = queueprocesses = []for j in range(k-1):processes.append(Process(target=sim, args=(int(j * d), int((j+1) * d), txt, pat, filename, patname, R, )))# processes.append(Process(target=sim, args=(int(j * d), len(txt), txt, pat, filename, patname, R, ))) for pr in processes:pr.start()for pr in processes:pr.join()while not R.empty():print (R.get())if __name__ == '__main__':R = Queue()main(R)
But, got error like:
AssertionError: Cannot start a process twice
Can somebody please help with this issue
full output:
sim(e_original.txt, e_modify0%.txt) = 0.000000
sim(e_original.txt, e_modify0%.txt) = 0.000000
1
Traceback (most recent call last):File "measure.py", line 108, in <module>main()File "measure.py", line 98, in mainpr.start()File "C:\Python27\lib\multiprocessing\process.py", line 120, in startassert self._popen is None, 'cannot start a process twice'
AssertionError: cannot start a process twice
sim(e_original.txt, e_modify0%.txt) = 0.000000