From ea39d366a3d57b46517a1617a96c96a3fccb7d12 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 6 Nov 2024 09:05:53 +0800 Subject: [PATCH] fix: `FileNotFoundError` with pdm run and process substitution (#3260) --- news/3252.bugfix.md | 1 + src/pdm/cli/commands/run.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 news/3252.bugfix.md diff --git a/news/3252.bugfix.md b/news/3252.bugfix.md new file mode 100644 index 0000000000..e66a3ff83c --- /dev/null +++ b/news/3252.bugfix.md @@ -0,0 +1 @@ +Inherit file descriptors instead of closing when running child processes in `pdm run`. diff --git a/src/pdm/cli/commands/run.py b/src/pdm/cli/commands/run.py index b2f011ec43..6dbb0e2366 100644 --- a/src/pdm/cli/commands/run.py +++ b/src/pdm/cli/commands/run.py @@ -292,11 +292,11 @@ def forward_signal(signum: int, frame: FrameType | None) -> None: handle_term = signal.signal(signal.SIGTERM, forward_signal) handle_int = signal.signal(signal.SIGINT, forward_signal) - process = subprocess.Popen(process_cmd, cwd=cwd, shell=shell, bufsize=0) - process.wait() + process = subprocess.Popen(process_cmd, cwd=cwd, shell=shell, bufsize=0, close_fds=False) + retcode = process.wait() signal.signal(signal.SIGTERM, handle_term) signal.signal(signal.SIGINT, handle_int) - return process.returncode + return retcode def run_task( self, task: Task, args: Sequence[str] = (), opts: TaskOptions | None = None, seen: set[str] | None = None