[Python] concurrent.futures.ProcessPoolExecutor hangs when the function is a lambda or nested...

Discussão em 'Python' iniciado por Stack, Abril 25, 2025.

  1. Stack

    Stack Membro Participativo

    Can anyone provide insight into why using lambda or a nested function (f) would make concurrent.futures.ProcessPoolExecutor hang in the following code example?

    import concurrent.futures


    def f2(s):
    return len(s)


    def main():
    def f(s):
    return len(s)

    data = ["a", "b", "c"]

    with concurrent.futures.ProcessPoolExecutor(max_workers=1) as pool:
    # results = pool.map(f, data) # hangs
    # results = pool.map(lambda d: len(d), data) # hangs
    # results = pool.map(len, data) # works
    results = pool.map(f2, data) # works

    print(list(results))


    if __name__ == "__main__":
    main()

    Continue reading...

Compartilhe esta Página