I’m having an issue where I need to decorate a function or method that shall be run in a background process. Example code is something like this:
from multiprocessing import Pool
pool = Pool()
def run_in_background (func):
def get_args (*args,**kwargs):
res = pool.apply(func,*args,**kwargs)
return res
return get_args
if __name__ == '__main__':
@run_in_background
def runner (n):
for i in range(n):
print(i)
runner(10)
When I run something like this, I get a pickle error showing that runner isn’t the same as __main__.runner
. Could there be a way to work around this and still maintain the decorator?