I would like to enhance question from “/questions/78538034/in-python-how-do-i-pass-local-variable-values-to-multiprocessing-librarys-pool?noredirect=1#comment138458954_78538034”
where I have similar problem as in related question, just enhanced that I call it from different file.
To example:
File1 Code:
import Code
result = Code.Main_Code()
print(result)
File2 Code:
from multiprocessing import Pool
def Multicore_Patterns_List_processor(args):
Variable1, Variable2, Variable3, Pattern = args
print(f"{Variable1=}, {Variable2=}, {Variable3=}, current pattern is {Pattern}")
def gen_args(Variable1, Variable2, Variable3):
for p in range(10):
yield Variable1, Variable2, Variable3, p
def Main_Code():
Variable1 = 1
Variable2 = 2
Variable3 = 3
MultiCores = 3
print("Finish of simple code and start of heavy code in parralel")
with Pool(processes=MultiCores) as pool:
pool.imap(Multicore_Patterns_List_processor, gen_args(Variable1, Variable2, Variable3))
pool.close()
pool.join()
print("Finish of heavy code and continue of simple code")
done = True
return done
This is not working.
I’m trying to reach the state where I let python by processed by single processor, because code is simple and later in the “Code.py” file there is an heavier code which allow be processed in parallel and thanks to this fact to speed time for Local function be processed (as the function is processed several times 10). After this python should continue in single processor to finish simple code.