I think my question was not very clear before.. I'm trying to create a class module that includes a function does a mutiprocessing of a ctpyes function.
I'm re-posting a working small code. All I want to do is to remove the code below and call the function directly from my class. But it seems very hard since ctypes object is not picklable.. Is there a way to resolve this issue? Even a small hint will be appreciated!! Will I have to switch to using cython instead of ctypes? will that even help?
def myc(x):
return a.funct(x)
Below is the working code.
from ctypes import *
from ctypes.util import find_library
import multiprocess as mp
class ctest():
def __init__(self):
self.libapr = cdll.LoadLibrary(find_library('apr-1'))
self.libapr.apr_fnmatch.argtypes = [c_char_p, c_char_p, c_int]
self.libapr.apr_fnmatch.restype = c_int
def funct(self,x):
y=self.libapr.apr_fnmatch(x, 'name.ext', 0)
return y
def mymult(self,func,xlist):
pool=mp.Pool(20)
res=pool.map(func,xlist)
pool.close()
return res
if __name__ == "__main__":
a=ctest()
def myc(x):return a.funct(x)
print a.mymult(myc,['*.txt','*.ext'])
Below is what I want to do.
from ctypes import *
from ctypes.util import find_library
import multiprocess as mp
class ctest():
def __init__(self):
self.libapr = cdll.LoadLibrary(find_library('apr-1'))
self.libapr.apr_fnmatch.argtypes = [c_char_p, c_char_p, c_int]
self.libapr.apr_fnmatch.restype = c_int
def funct(self,x):
y=self.libapr.apr_fnmatch(x, 'name.ext', 0)
return y
def mymult(self,func,xlist):
pool=mp.Pool(20)
res=pool.map(func,xlist)
pool.close()
return res
if __name__ == "__main__":
a=ctest()
a.mymult(a.funct,['*.txt','*.ext'])