Python 3.8并发.futures“OSError:句柄已关闭”

A. *_*dry 9 python-3.x concurrent.futures oserror

我有 Python 3.8 并且无法升级(我有仅适用于 Python 3.8 的依赖项),所以这篇 SO 帖子没有回答我的问题。我该如何防止该OSError: handle is closed错误?当将结果返回到主线程时会发生这种情况。这是一个非常简单的例子:

from concurrent.futures import ProcessPoolExecutor


def my_func(num):
    return num + 1


def worker(data):
    with ProcessPoolExecutor(5) as executor:
        result = executor.map(my_func, data)
    return result


if __name__ == "__main__":
    arr = [1, 2, 3, 4, 5]
    print(arr)
    arr = worker(arr)
    print(tuple(arr))
Run Code Online (Sandbox Code Playgroud)

这给出了

[1, 2, 3, 4, 5]
(2, 3, 4, 5, 6)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Users\hendra11\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\process.py", line 102, in _python_exit
    thread_wakeup.wakeup()
  File "C:\Users\hendra11\AppData\Local\Programs\Python\Python38\lib\concurrent\futures\process.py", line 90, in wakeup
    self._writer.send_bytes(b"")
  File "C:\Users\hendra11\AppData\Local\Programs\Python\Python38\lib\multiprocessing\connection.py", line 183, in send_bytes
    self._check_closed()
  File "C:\Users\hendra11\AppData\Local\Programs\Python\Python38\lib\multiprocessing\connection.py", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed
Run Code Online (Sandbox Code Playgroud)

有谁知道导致此错误的原因以及如何手动修复它?

如果重要的话,我在 Windows 10 上运行 Visual Studio Code。

更新:ThreadPoolExecutor当我使用并且速度更快时,此错误消失,但我不知道为什么。