I've successfully implemented a multiprocessed script on Windows, but the same script launches a "RuntimeError: already started" on linux and stops the execution. The script consists of the following "main.py" (omitted some part for readability):
from multiprocessing import freeze_support
if __name__ == '__main__':
#MULTIPROCESSING STUFF
freeze_support()
#DO SOME STUFF
#Call my multiprocessing-function in other module
mod2.func(tileTS[0], label, areaconst)
And the "mod2.py" module:
import numpy as np
from multiprocessing import Pool
from functools import partial
import os, time
def func(ts, label, areaconst):
#SETTING UP/LOADING SOME VARIABLES
for idx in totImgs:
img_ = myList[idx]
p = Pool(2)
result = p.map( partial(_mp_avg, var1=var1_, img=img_), range(totObjs) )
p.close()
p.join()
#MANAGE RESULTING VARIABLES
return None
def _mp_avg(idx, img, var1):
num = idx + 1
arr = img[var1==num]
if np.isnan(arr).any():
return np.nan
else:
return np.sum( arr )
This error is launched when the script executes the "Pool.map" function/class (dunno tbh). The same code works flawlessly on Windows.
I'm using Ubuntu 18.04 and launching the python 3.6.7 script from Visual Studio Code.