I have a class that is implemented in cython containing c pointers that I am trying to use with the python multiprocessing module. The class returns a DLL file for returning an instance of the class.
The problem is that while the instances keep their data type, they seem empty, that is, I can access all of their class functions, but they lost all their instance values ββthat I installed before they were entered. The code containing special_class is very large, so I cannot 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()
The above script gives me the output
None
None
The correct conclusion should be in style
name.a
name.b
If I create instances inside the run_task function, it will work fine, but I'm looking for a way to make it work by creating instances in the main process. Is it possible?