I'm doing some multiprocessing in Python, using classes, and to do such thing I had to use this approach:
def _pickle_method(method):
func_name = method.im_func.__name__
obj = method.im_self
cls = method.im_class
if func_name.startswith('__') and not func_name.endswith('__'): #deal with mangled names
cls_name = cls.__name__.lstrip('_')
func_name = '_' + cls_name + func_name
print cls
return _unpickle_method, (func_name, obj, cls)
def _unpickle_method(func_name, obj, cls):
for cls in cls.__mro__:
try:
func = cls.__dict__[func_name]
except KeyError:
pass
else:
break
return func.__get__(obj, cls)
The problem is 'cause I have some static methods that should parallelized too. But I found that with this I can't pickle static methods. I'm wondering it there is a way to change this methods to do such thing, so I could pickle both non-static and static methods.
Thank you in advance.