summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* Add note on capture_output arg to subprocess.run() docstring (#98012)andrei kulakov2022-10-071-1/+2
| | | add note on capture_output arg to the docstring
* gh-97825: fix AttributeError when calling ↵andrei kulakov2022-10-051-1/+2
| | | | | subprocess.check_output(input=None) with encoding or errors args (#97826) * fix AttributeError, add unit test
* gh-95174: Handle missing waitpid and gethostbyname in WASI (GH-95181)Christian Heimes2022-07-241-6/+17
|
* gh-90473: Fail subprocess early on Emscripten/WASI (GH-92802)Christian Heimes2022-05-141-6/+11
|
* gh-57684: Add -P cmdline option and PYTHONSAFEPATH env var (#31542)Victor Stinner2022-05-051-2/+4
| | | | | | | | | | | | Add the -P command line option and the PYTHONSAFEPATH environment variable to not prepend a potentially unsafe path to sys.path. * Add sys.flags.safe_path flag. * Add PyConfig.safe_path member. * Programs/_bootstrap_python.c uses config.safe_path=0. * Update subprocess._optim_args_from_interpreter_flags() to handle the -P command line option. * Modules/getpath.py sets safe_path to 1 if a "._pth" file is present.
* gh-82616: Add process_group support to subprocess.Popen (#23930)Gregory P. Smith2022-05-051-5/+12
| | | | | | | | 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>
* gh-91954: Emit EncodingWarning from locale and subprocess (GH-91977)Inada Naoki2022-04-301-10/+28
| | | locale.getpreferredencoding() and subprocess.Popen() emit EncodingWarning
* gh-91401: Add a failsafe way to disable vfork. (#91490)Gregory P. Smith2022-04-251-1/+4
| | | | | | | | | | | | | | Just in case there is ever an issue with _posixsubprocess's use of vfork() due to the complexity of using it properly and potential directions that Linux platforms where it defaults to on could take, this adds a failsafe so that users can disable its use entirely by setting a global flag. No known reason to disable it exists. But it'd be a shame to encounter one and not be able to use CPython without patching and rebuilding it. See the linked issue for some discussion on reasoning. Also documents the existing way to disable posix_spawn.
* bpo-40280: Emscripten fork_exec now fails early (GH-32224)Christian Heimes2022-04-011-2/+8
|
* bpo-40280: Use presence of msvcrt module to detect Windows (GH-30930)Christian Heimes2022-01-271-2/+7
|
* bpo-40280: Change subprocess imports for cleaner error on wasm32 (GH-30620)Christian Heimes2022-01-171-8/+7
|
* bpo-40497: Fix handling of check in subprocess.check_output() (GH-19897)Rémi Lapeyre2021-09-201-2/+3
| | | | Co-authored-by: Tal Einat <taleinat@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-44935: enable posix_spawn() on Solaris (GH-27795)Jakub Kulík2021-08-171-2/+3
| | | Enable posix_spawn() on Solaris
* Fix typos in multiple files (GH-26689)Binbin2021-06-131-1/+1
| | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-43776: Remove list call from args in Popen repr (GH-25338)M. Kocher2021-04-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Removes the `list` call in the Popen `repr`. Current implementation: For cmd = `python --version`, with `shell=True`. ```bash <Popen: returncode: None args: ['p', 'y', 't', 'h', 'o', 'n', ' ', '-', '-',...> ``` For `shell=False` and args=`['python', '--version']`, the output is correct: ```bash <Popen: returncode: None args: ['python', '--version']> ``` With the new changes the `repr` yields: For cmd = `python --version`, with `shell=True`: ```bash <Popen: returncode: None args: 'python --version'> ``` For `shell=False` and args=`['python', '--version']`, the output: ```bash <Popen: returncode: None args: ['python', '--version']> ``` Automerge-Triggered-By: GH:gpshead
* bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)Inada Naoki2021-03-291-1/+8
| | | | | | | | | | | See [PEP 597](https://www.python.org/dev/peps/pep-0597/). * Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`. * Add EncodingWarning * Add io.text_encoding() * open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled. * _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python) * bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding(). * What's new entry
* bpo-41718: subprocess imports grp and pwd on demand (GH-24987)Victor Stinner2021-03-231-12/+9
| | | | | The shutil and subprocess modules now only import the grp and pwd modules when they are needed, which is not the case by default in subprocess.
* bpo-43423 Fix IndexError in subprocess _communicate function (GH-24777)Chris Griffith2021-03-111-4/+2
| | | | | Check to make sure stdout and stderr are not empty before selecting an item from them in Windows subprocess._communicate. Co-authored-by: Gregory P. Smith <greg@krypto.org>
* bpo-43391: Remove the broken Python 2.4 link from the comment (GH-24736)Kamil Turek2021-03-041-1/+0
|
* bpo-42388: Fix subprocess.check_output input=None when text=True (GH-23467)Gregory P. Smith2020-12-251-1/+5
| | | | | | | | | | When the modern text= spelling of the universal_newlines= parameter was added for Python 3.7, check_output's special case around input=None was overlooked. So it behaved differently with universal_newlines=True vs text=True. This reconciles the behavior to be consistent and adds a test to guarantee it. Also clarifies the existing check_output documentation. Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
* bpo-40550: Fix time-of-check/time-of-action issue in ↵Filipe Laíns2020-11-211-1/+5
| | | | | | | subprocess.Popen.send_signal. (GH-20010) send_signal() now swallows the exception if the process it thought was still alive winds up not to exist anymore (always a plausible race condition despite the checks). Co-authored-by: Gregory P. Smith <greg@krypto.org>
* bpo-41586: Add pipesize parameter to subprocess & F_GETPIPE_SZ and ↵Ruben Vorderman2020-10-191-1/+18
| | | | | | | | | | | | | | | | | F_SETPIPE_SZ to fcntl. (GH-21921) * Add F_SETPIPE_SZ and F_GETPIPE_SZ to fcntl module * Add pipesize parameter for subprocess.Popen class This will allow the user to control the size of the pipes. On linux the default is 64K. When a pipe is full it blocks for writing. When a pipe is empty it blocks for reading. On processes that are very fast this can lead to a lot of wasted CPU cycles. On a typical Linux system the max pipe size is 1024K which is much better. For high performance-oriented libraries such as xopen it is nice to be able to set the pipe size. The workaround without this feature is to use my_popen_process.stdout.fileno() in conjuction with fcntl and 1031 (value of F_SETPIPE_SZ) to acquire this behavior.
* bpo-40939: Remove the old parser (GH-20768)Pablo Galindo2020-06-111-1/+1
| | | This commit removes the old parser, the deprecated parser module, the old parser compatibility flags and environment variables and all associated support code and documentation.
* bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670)Victor Stinner2020-04-231-1/+1
| | | | | | | | | | | * Rename PyConfig.use_peg to _use_peg_parser * Document PyConfig._use_peg_parser and mark it a deprecated * Mark -X oldparser option and PYTHONOLDPARSER env var as deprecated in the documentation. * Add use_old_parser() and skip_if_new_parser() to test.support * Remove sys.flags.use_peg: use_old_parser() uses _testinternalcapi.get_configs() instead. * Enhance test_embed tests * subprocess._args_from_interpreter_flags() copies -X oldparser
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-21/+3
| | | | | | | | | | | | This implements things like `list[int]`, which returns an object of type `types.GenericAlias`. This object mostly acts as a proxy for `list`, but has attributes `__origin__` and `__args__` that allow recovering the parts (with values `list` and `(int,)`. There is also an approximate notion of type variables; e.g. `list[T]` has a `__parameters__` attribute equal to `(T,)`. Type variables are objects of type `typing.TypeVar`.
* bpo-40094: Add os.waitstatus_to_exitcode() (GH-19201)Victor Stinner2020-04-011-12/+6
| | | | | | | | | | | | | | Add os.waitstatus_to_exitcode() function to convert a wait status to an exitcode. Suggest waitstatus_to_exitcode() usage in the documentation when appropriate. Use waitstatus_to_exitcode() in: * multiprocessing, os, subprocess and _bootsubprocess modules; * test.support.wait_process(); * setup.py: run_command(); * and many tests.
* bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)Victor Stinner2020-02-031-1/+1
| | | | | | | | | | | Remove: * COUNT_ALLOCS macro * sys.getcounts() function * SHOW_ALLOC_COUNT code in listobject.c * SHOW_TRACK_COUNT code in tupleobject.c * PyConfig.show_alloc_count field * -X showalloccount command line option * @test.support.requires_type_collecting decorator
* bpo-35182: fix communicate() crash after child closes its pipes (GH-17020) ↵Alex Rebert2020-01-221-2/+2
| | | | | | | | | (GH-18117) When communicate() is called in a loop, it crashes when the child process has already closed any piped standard stream, but still continues to be running Co-authored-by: Andriy Maletsky <andriy.maletsky@gmail.com>
* bpo-38630: Fix subprocess.Popen.send_signal() race condition (GH-16984)Victor Stinner2020-01-151-3/+25
| | | | | | | On Unix, subprocess.Popen.send_signal() now polls the process status. Polling reduces the risk of sending a signal to the wrong process if the process completed, the Popen.returncode attribute is still None, and the pid has been reassigned (recycled) to a new different process.
* bpo-39019: Implement missing __class_getitem__ for subprocess classes (GH-17558)Batuhan Taşkaya2019-12-301-0/+24
|
* bpo-38724: Implement subprocess.Popen.__repr__ (GH-17151)Andrey Doroschenko2019-11-171-0/+9
|
* bpo-38417: Add umask support to subprocess (GH-16726)Gregory P. Smith2019-10-121-5/+9
| | | | On POSIX systems, allow the umask to be set in the child process before we exec.
* bpo-36046: posix_spawn() doesn't support uid/gid (GH-16384)Victor Stinner2019-09-251-1/+4
| | | | | * subprocess.Popen now longer uses posix_spawn() if uid, gid or gids are set. * test_subprocess: add "nobody" and "nfsnobody" group names for test_group(). * test_subprocess: test_user() and test_group() are now also tested with close_fds=False.
* bpo-36046: Add user and group parameters to subprocess (GH-11950)Patrick McLean2019-09-121-5/+100
| | | | | | | | | | | | | | * subprocess: Add user, group and extra_groups paremeters to subprocess.Popen This adds a `user` parameter to the Popen constructor that will call setreuid() in the child before calling exec(). This allows processes running as root to safely drop privileges before running the subprocess without having to use a preexec_fn. This also adds a `group` parameter that will call setregid() in the child process before calling exec(). Finally an `extra_groups` parameter was added that will call setgroups() to set the supplimental groups.
* bpo-37424: Avoid a hang in subprocess.run timeout output capture (GH-14490)Gregory P. Smith2019-09-111-9/+27
| | | | | | | Fixes a possible hang when using a timeout on subprocess.run() while capturing output. If the child process spawned its own children or otherwise connected its stdout or stderr handles with another process, we could hang after the timeout was reached and our child was killed when attempting to read final output from the pipes.
* Fix subprocess docstring typo (GH-15812)Matthias2019-09-101-1/+1
|
* bpo-37380: subprocess: don't use _active on win (GH-14360)Ruslan Kuprieiev2019-06-281-16/+32
| | | | | | | | | | | | | | | | | | | As noted by @eryksun in [1] and [2], using _cleanup and _active(in __del__) is not necessary on Windows, since: > Unlike Unix, a process in Windows doesn't have to be waited on by > its parent to avoid a zombie. Keeping the handle open will actually > create a zombie until the next _cleanup() call, which may be never > if Popen() isn't called again. This patch simply defines `subprocess._active` as `None`, for which we already have the proper logic in place in `subprocess.Popen.__del__`, that prevents it from trying to append the process to the `_active`. This patch also defines `subprocess._cleanup` as a noop for Windows. [1] https://bugs.python.org/issue37380#msg346333 [2] https://bugs.python.org/issue36067#msg336262 Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai>
* bpo-37363: Add audit events for a range of modules (GH-14301)Steve Dower2019-06-241-1/+8
|
* bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)Rémi Lapeyre2019-06-081-2/+2
| | | | | | Fix an unintended ValueError from :func:`subprocess.run` when checking for conflicting `input` and `stdin` or `capture_output` and `stdout` or `stderr` args when they were explicitly provided but with `None` values within a passed in `**kwargs` dict rather than as passed directly by name.
* bpo-31961: Fix support of path-like executables in subprocess. (GH-5914)Serhiy Storchaka2019-05-281-3/+22
|
* bpo-36793: Remove unneeded __str__ definitions. (GH-13081)Serhiy Storchaka2019-05-061-1/+0
| | | | Classes that define __str__ the same as __repr__ can just inherit it from object.
* subprocess: close pipes/fds by using ExitStack (GH-11686)Giampaolo Rodola2019-01-291-17/+18
| | | | | | | Close pipes/fds in subprocess by using ExitStack. "In case of premature failure on X.Close() or os.close(X) the remaining pipes/fds will remain "open". Perhaps it makes sense to use contextlib.ExitStack." - Rationale: https://github.com/python/cpython/pull/11575#discussion_r250288394
* Fix docstr/comment typos in _use_posix_spawn(). (GH-11684)Gregory P. Smith2019-01-261-11/+10
|
* bpo-35537: subprocess can use posix_spawn with pipes (GH-11575)Victor Stinner2019-01-231-28/+64
| | | | | | * subprocess.Popen can now also use os.posix_spawn() with pipes, but only if pipe file descriptors are greater than 2. * Fix Popen._posix_spawn(): set '_child_created' attribute to True. * Add Popen._close_pipe_fds() helper function to factorize the code.
* Revert "bpo-35537: subprocess can now use os.posix_spawnp (GH-11579)" (GH-11582)Victor Stinner2019-01-161-10/+3
| | | This reverts commit 07858894689047c77f9c12ddc061d30681368d19.
* bpo-35537: subprocess can now use os.posix_spawnp (GH-11579)Victor Stinner2019-01-161-3/+10
| | | | The subprocess module can now use the os.posix_spawnp() function, if it is available, to locate the program in the PATH.
* bpo-35537: subprocess uses os.posix_spawn in some cases (GH-11452)Victor Stinner2019-01-151-0/+82
| | | | | | | | | | | | The subprocess module can now use the os.posix_spawn() function in some cases for better performance. Currently, it is only used on macOS and Linux (using glibc 2.24 or newer) if all these conditions are met: * executable path contains a directory * close_fds=False * preexec_fn, pass_fds, cwd, stdin, stdout, stderr and start_new_session parameters are not set Co-authored-by: Joannah Nanjekye <nanjekyejoannah@gmail.com>
* bpo-34812: subprocess._args_from_interpreter_flags(): add isolated (GH-10675)Victor Stinner2018-11-231-2/+8
| | | | | | | | The "-I" command line option (run Python in isolated mode) is now also copied by the multiprocessing and distutils modules when spawning child processes. Previously, only -E and -s options (enabled by -I) were copied. subprocess._args_from_interpreter_flags() now copies the -I flag.
* bpo-32236: open() emits RuntimeWarning if buffering=1 for binary mode (GH-4842)Alexey Izbyshev2018-10-201-1/+10
| | | | | | | | | If buffering=1 is specified for open() in binary mode, it is silently treated as buffering=-1 (i.e., the default buffer size). Coupled with the fact that line buffering is always supported in Python 2, such behavior caused several issues (e.g., bpo-10344, bpo-21332). Warn that line buffering is not supported if open() is called with binary mode and buffering=1.
* closes bpo-32490: Fix filename duplication in subprocess exception message. ↵Zackery Spytz2018-09-111-2/+0
| | | | | (GH-9163) 8621bb5d93239316f97281826461b85072ff6db7 sets the filename in directly in the FileNotFoundError, so we may revert the earlier fix 5f780400572508a8179de6a6c13b58b7be417ef5.