This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bob.fang.london
Recipients bob.fang.london
Date 2020-08-18.17:21:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1597771306.07.0.252837170253.issue41577@roundup.psfhosted.org>
In-reply-to
Content
I have this minimal example:

```
from functools import wraps
from concurrent import futures
import random

def decorator(func):
    num_process = 4

    def impl(*args, **kwargs):
        with futures.ProcessPoolExecutor() as executor:
            fs = []
            for i in range(num_process):
                fut = executor.submit(func, *args, **kwargs)
                fs.append(fut)
            result = []
            for f in futures.as_completed(fs):
                result.append(f.result())
        return result
    return impl

@decorator
def get_random_int():
    return random.randint(0, 100)


if __name__ == "__main__":
    result = get_random_int()
    print(result)
```
If we try to run this function I think we will have the following error:
```
_pickle.PicklingError: Can't pickle <function get_random_int at 0x7f06cee666a8>: it's not the same object as __main__.get_random_int
```
I think the main issue here is that the "wraps" decorator itself alters the `func` object and thus make it impossible to pickle. I found this rather strange. I am just wondering if there is any way to get around this behavior? I would want to use `wraps` if possible. Thanks!
History
Date User Action Args
2020-08-18 17:21:46bob.fang.londonsetrecipients: + bob.fang.london
2020-08-18 17:21:46bob.fang.londonsetmessageid: <1597771306.07.0.252837170253.issue41577@roundup.psfhosted.org>
2020-08-18 17:21:46bob.fang.londonlinkissue41577 messages
2020-08-18 17:21:45bob.fang.londoncreate