diff options
author | Gregory P. Smith <greg@krypto.org> | 2022-05-05 23:22:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 23:22:32 (GMT) |
commit | f6dd14c65336cda4e2ebccbc6408dfe3b0a68a34 (patch) | |
tree | 75e0b51fc5787a7ba02cf1f0534b292fb9a0a528 /Lib/subprocess.py | |
parent | 49fda0cc51c09e26d68431d5f86e11d923cf7b8e (diff) | |
download | cpython-f6dd14c65336cda4e2ebccbc6408dfe3b0a68a34.zip cpython-f6dd14c65336cda4e2ebccbc6408dfe3b0a68a34.tar.gz cpython-f6dd14c65336cda4e2ebccbc6408dfe3b0a68a34.tar.bz2 |
gh-82616: Add process_group support to subprocess.Popen (#23930)
One more thing that can help prevent people from using `preexec_fn`.
Also adds conditional skips to two tests exposing ASAN flakiness on the Ubuntu 20.04 Address Sanitizer Github CI system. When that build is run on more modern systems the "problem" does not show up. It seems ASAN implementation related.
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 968cfc1..9099822 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -769,6 +769,8 @@ class Popen: start_new_session (POSIX only) + process_group (POSIX only) + group (POSIX only) extra_groups (POSIX only) @@ -794,7 +796,8 @@ class Popen: startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, user=None, group=None, extra_groups=None, - encoding=None, errors=None, text=None, umask=-1, pipesize=-1): + encoding=None, errors=None, text=None, umask=-1, pipesize=-1, + process_group=None): """Create new Popen instance.""" _cleanup() # Held while anything is calling waitpid before returncode has been @@ -900,6 +903,9 @@ class Popen: else: line_buffering = False + if process_group is None: + process_group = -1 # The internal APIs are int-only + gid = None if group is not None: if not hasattr(os, 'setregid'): @@ -1003,7 +1009,7 @@ class Popen: errread, errwrite, restore_signals, gid, gids, uid, umask, - start_new_session) + start_new_session, process_group) except: # Cleanup if the child failed starting. for f in filter(None, (self.stdin, self.stdout, self.stderr)): @@ -1387,7 +1393,7 @@ class Popen: unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, - unused_start_new_session): + unused_start_new_session, unused_process_group): """Execute program (MS Windows version)""" assert not pass_fds, "pass_fds not supported on Windows." @@ -1719,7 +1725,7 @@ class Popen: errread, errwrite, restore_signals, gid, gids, uid, umask, - start_new_session): + start_new_session, process_group): """Execute program (POSIX version)""" if isinstance(args, (str, bytes)): @@ -1755,6 +1761,7 @@ class Popen: and (c2pwrite == -1 or c2pwrite > 2) and (errwrite == -1 or errwrite > 2) and not start_new_session + and process_group == -1 and gid is None and gids is None and uid is None @@ -1812,7 +1819,7 @@ class Popen: errread, errwrite, errpipe_read, errpipe_write, restore_signals, start_new_session, - gid, gids, uid, umask, + process_group, gid, gids, uid, umask, preexec_fn, _USE_VFORK) self._child_created = True finally: |