I have a set of objects which do some computing and plotting - they run in threads.
After all threads join()
, I want to access class attributes of the objects from my main function.
This is small example
import multiprocessing
import numpy as np
class Foo(object):
def __init__(self, i):
self.i = i
def run(self):
self.l = np.empty([1024])
self.l.fill(self.i)
foos = []
threads = []
for i in range(8):
foo = Foo(i)
foos.append(foo)
thread = multiprocessing.Process(target=foo.run)
thread.start()
[thread.join() for thread in threads]
print [foo.l for foo in foos] # AttributeError: 'Foo' object has no attribute 'l'
I saw this post: how to get the return value from a thread in python? But it requires the method to have a return value.