Function decorators don't work well with multiprocessing

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?

What OS? At least on Windows, the multiprocessing code, which here are the calls to Pool and pool.apply, must be in the main clause. A decorator is a convenience shortcut for calling the function wrapper after defining a function. If the convenience causes a but, it is not really convenient.

I’m actually using windows, basically this is the error I get