0
votes

So I let's say I have a Python class:

class Something:
    def __init__(self, a, b, c):
        initialize_object_with_args()

    def run(self):
        do_something()

    def result(self):
        return result

Now I want to create multiple objects of that class (all of which are independent - no need for data exchange between the objects) and run them in parallel on a single PC with a multicore CPU...the only thing changing are the input arguments (a,b, c) for each run...

So I would need this:

results = []
[PARALLEL START]
    obj = Something(a, b, c)
    obj.run()
    results.append(obj.results())
[PARALLEL END]

I could then evaluate the results! I see that the multiprocessing module would be what I need but i don't know the specifics nor if it can do what I need nor how?

Quick Edit: I need to be able to do this with Python...no external modules...just the standard Python install...

2

2 Answers

0
votes
0
votes

It seems to be very similar to this

from multiprocessing import Pool

def func(*args):
    obj = Something(*args)
    obj.run()
    return obj.results()

pool = Pool()
results = pool.map(func, ((1,2,3), (4,5,6)))