Skip to content

Cannot use multiprocessing-based python code as a function argument on windows ? #91573

Closed as not planned
@antoinecarme

Description

@antoinecarme

Dear all,

I am developing a data library that uses multiprocessing internally.

https://github.com/antoinecarme/pyaf

The code based on this library works flawlessly on linux, but some users, including myself, cannot execute it on Windows (with different versions of python : 3.8, 3.9, 3.10).

antoinecarme/pyaf#156

This seems to be a general buggy pattern. A function that uses mutliprocessing cannot be called from another function.

I reduced the code to get something that demonstrates this issue, the code below works on debian but not on windows (python 3.10, downloaded yesterday from python website and installed on windows 10)

from multiprocessing import Pool

def f(x):
    return x*x

def g(K, N):
    # Any external function that uses multiprocessing can be used here.
    with Pool(K) as p:
        x = p.map(f, [x for x in range(N)])
        return x
    
# mix of different multiprocessing tasks.
# expected output : [0, 1, 0, 1, 4]
print(g(3,2) + g(2, 3))

The expected output is copy-pasted from debian. this is a very blocking issue for Windows users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions