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>
This commit is contained in:
Gregory P. Smith 2022-05-05 16:22:32 -07:00 committed by GitHub
parent 49fda0cc51
commit f6dd14c653
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 73 additions and 28 deletions

View file

@ -344,7 +344,8 @@ functions.
startupinfo=None, creationflags=0, restore_signals=True, \
start_new_session=False, pass_fds=(), *, group=None, \
extra_groups=None, user=None, umask=-1, \
encoding=None, errors=None, text=None, pipesize=-1)
encoding=None, errors=None, text=None, pipesize=-1, \
process_group=None)
Execute a child program in a new process. On POSIX, the class uses
:meth:`os.execvpe`-like behavior to execute the child program. On Windows,
@ -500,18 +501,16 @@ functions.
.. warning::
The *preexec_fn* parameter is not safe to use in the presence of threads
The *preexec_fn* parameter is NOT SAFE to use in the presence of threads
in your application. The child process could deadlock before exec is
called.
If you must use it, keep it trivial! Minimize the number of libraries
you call into.
.. note::
If you need to modify the environment for the child use the *env*
parameter rather than doing it in a *preexec_fn*.
The *start_new_session* parameter can take the place of a previously
common use of *preexec_fn* to call os.setsid() in the child.
The *start_new_session* and *process_group* parameters should take the place of
code using *preexec_fn* to call :func:`os.setsid` or :func:`os.setpgid` in the child.
.. versionchanged:: 3.8
@ -568,12 +567,20 @@ functions.
.. versionchanged:: 3.2
*restore_signals* was added.
If *start_new_session* is true the setsid() system call will be made in the
child process prior to the execution of the subprocess. (POSIX only)
If *start_new_session* is true the ``setsid()`` system call will be made in the
child process prior to the execution of the subprocess.
.. availability:: POSIX
.. versionchanged:: 3.2
*start_new_session* was added.
If *process_group* is a non-negative integer, the ``setpgid(0, value)`` system call will
be made in the child process prior to the execution of the subprocess.
.. availability:: POSIX
.. versionchanged:: 3.11
*process_group* was added.
If *group* is not ``None``, the setregid() system call will be made in the
child process prior to the execution of the subprocess. If the provided
value is a string, it will be looked up via :func:`grp.getgrnam()` and