diff --git a/Lib/multiprocessing/popen_spawn_posix.py b/Lib/multiprocessing/popen_spawn_posix.py index 24b8634523e5f2..7c0377035baa6a 100644 --- a/Lib/multiprocessing/popen_spawn_posix.py +++ b/Lib/multiprocessing/popen_spawn_posix.py @@ -32,7 +32,9 @@ def __init__(self, process_obj): super().__init__(process_obj) def duplicate_for_child(self, fd): - self._fds.append(fd) + # duplicates in self._fds would later lead to a ValueError + if fd not in self._fds: + self._fds.append(fd) return fd def _launch(self, process_obj): diff --git a/Misc/NEWS.d/next/Library/2021-02-06-06-43-52.bpo-43142.Gt_6Yb.rst b/Misc/NEWS.d/next/Library/2021-02-06-06-43-52.bpo-43142.Gt_6Yb.rst new file mode 100644 index 00000000000000..87ec85faa69209 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-02-06-06-43-52.bpo-43142.Gt_6Yb.rst @@ -0,0 +1 @@ +Do not add duplicate FDs to list in duplicate_for_child() in order to avoid ValueError: bad value(s) in fds_to_keep \ No newline at end of file