I have a class that is implemented in cython containing c-pointers which I'm trying to use together with python's multiprocessing module. The class takes a DLL-file to return an instance of the class.
The problem I have is that while the instances preserve their data type, they seem to be empty, i.e. I can access all their class functions but they've lost all their instance values I set before they entered. The code containing special_class is very big so I'm not able to include it.
import time
import multiprocessing as mp
from special_module import special_class
def run_task(tasks,nr):
obj = tasks[nr]['data']
print obj.get_name()
if __name__ == "__main__":
m1 = special_class("a.dll")
m2 = special_class("b.dll")
tasks = dict()
tasks[1] = {'data': m1}
tasks[2] = {'data': m2}
process1 = mp.Process(target = run_task, name = 'process1', args = (tasks, 1))
process2 = mp.Process(target = run_task, name = 'process2', args = (tasks, 2))
process1.start()
time.sleep(0.2)
process2.start()
process1.join()
process2.join()
Above script gives me the output
None
None
The correct output should be in the style of
name.a
name.b
If I create the instances inside the function run_task it will work fine, but I'm looking for a way to make it work by creating the instances in the main process. Is this possible?