From 9d365ba4b32166ddc67758bc2ccd7703a408c55d Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Thu, 24 Dec 2020 22:26:17 -0800 Subject: [PATCH] bpo-38435: Detect preexec_fn=os.setsid as start_new_session=True This is a somewhat common use case, this makes it more reliable. --- Lib/subprocess.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index e259dc3a8e5..c39d98104b3 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -937,6 +937,10 @@ class Popen(object): if uid < 0: raise ValueError(f"User ID cannot be negative, got {uid}") + if preexec_fn == os.setsid: # A common unnecessary legacy use. + start_new_session = True + preexec_fn = None + try: if p2cwrite != -1: self.stdin = io.open(p2cwrite, 'wb', bufsize)