Multi-processing with decorated methods - the parameter is incorrect
python pickling needs to pull the original function in order to re-construct the decorated function, and it's no longer in the namespace (because it's already been decorated.) using the decorator functools.wraps
on the wrapped function stores a copy of the original function in the __dict__ of the new function so it can be accessed later. There's some edge cases where this may not work (classes..) but for simple decorators, it should work:
from multiprocessing import Process
import functools
def profiler(func):
@functools.wraps(func)
def wrap(*args, **kwargs):
result = func(*args, **kwargs)
print("I profiled your function for you :)")
return result
return wrap
@profiler
def go_around(num):
print(num)
if __name__ == '__main__':
p = Process(target=go_around, args=(1,))
p.start()
p.join()
This answer discusses things a bit further..