I have a class with a method foo()
, and a dictionary
with a bunch of objects of that class.
How can I parallelize the execution of foo()
in my collection of objects?
class MyClass:
def __init__(self,a):
self.a = a
def foo():
self.a+=1
if __name__ == "__main__":
#get a dictionary full of independent objects
dic={}
for kk in range(10):
dic[kk]=MyClass(kk)
#execute foo on each object.
#How to do it in a parallel way?
for myObject in dic.values():
myObject.foo()
pd: this is probably a silly question, really simple in other programing languages, but I did google on the internet and did not find any straight forward solution.
You didn't provide a code sample so I'll give you some pseudo code but this should give you an idea of how to solve it: