I have struggle with using multiprocessing lib in Python, where I want to use Pool.
I have sample code which demonstrate my problem (actuall code is far more complex, but would not be helpfull in demonstration example)
Code:
<code>def Multicore_Patterns_List_processor(Variable1, Variable2, Variable3):
print(f"Variable1 = {Variable1}, Variable2 = {Variable2}, Variable3 = {Variable3}, current pattern is {Pattern}")
Variable1 = 1
Variable2 = 2
Variable3 = 3
MultiCores = 3
Paterns_list = list(range(1, 21))
with Pool(processes=MultiCores) as pool:
pool.imap(Multicore_Patterns_List_processor(Variable1=Variable1, Variable2=Variable2, Variable3=Variable3), Paterns_list)
</code>
<code>def Multicore_Patterns_List_processor(Variable1, Variable2, Variable3):
print(f"Variable1 = {Variable1}, Variable2 = {Variable2}, Variable3 = {Variable3}, current pattern is {Pattern}")
Variable1 = 1
Variable2 = 2
Variable3 = 3
MultiCores = 3
Paterns_list = list(range(1, 21))
with Pool(processes=MultiCores) as pool:
pool.imap(Multicore_Patterns_List_processor(Variable1=Variable1, Variable2=Variable2, Variable3=Variable3), Paterns_list)
</code>
def Multicore_Patterns_List_processor(Variable1, Variable2, Variable3):
print(f"Variable1 = {Variable1}, Variable2 = {Variable2}, Variable3 = {Variable3}, current pattern is {Pattern}")
Variable1 = 1
Variable2 = 2
Variable3 = 3
MultiCores = 3
Paterns_list = list(range(1, 21))
with Pool(processes=MultiCores) as pool:
pool.imap(Multicore_Patterns_List_processor(Variable1=Variable1, Variable2=Variable2, Variable3=Variable3), Paterns_list)
What should code do:
- Code should hand over all Variable which are defined as Variable.. and also the aactual Pattern which is selected, but I don’t know how to do it.
- there is no need to change Variable1 .. values as these are in the example used to demonstrate a need to transfer some variables to each Call.
- Why Pool –> because in real code I use also variable for different processes which select number of processors dynamically
Thank you for any help
Jan Vaško
Expectation is that each processing of function will work with Variables and also the iterator used for multiprocessing.