summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-128342: Specify timeout unit in subprocess docstrings (GH-128343)n-l-i2024-12-301-3/+3
| | | | | Specify timeout unit (seconds) in subprocess docstrings Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* gh-121381 Remove subprocess._USE_VFORK escape hatch (#121383)Cody Maloney2024-07-311-2/+1
| | | | | | | | | | | This flag was added as an escape hatch in gh-91401 and backported to Python 3.10. The flag broke at some point between its addition and now. As there is currently no publicly known environments that require this, remove it rather than work on fixing it. This leaves the flag in the subprocess module to not break code which may have used / checked the flag itself. discussion: https://discuss.python.org/t/subprocess-use-vfork-escape-hatch-broken-fix-or-remove/56915/2
* gh-120417: Fix "imported but unused" linter warnings (#120461)Victor Stinner2024-06-141-1/+1
| | | | | | | | | | | Add __all__ to the following modules: importlib.machinery, importlib.util and xml.sax. Add also "# noqa: F401" in collections.abc, subprocess and xml.sax. * Sort __all__; remove collections.abc.__all__; remove private names * Add tests
* GH-118844: Fix build failures when combining --disable-gil with ↵Savannah Ostrowski2024-05-111-1/+1
| | | | --enable-experimental-jit (GH-118935)
* gh-118293: Suppress mouse cursor feedback when launching Windows processes ↵Henrik Tunedal2024-04-281-0/+2
| | | | with multiprocessing (GH-118315)
* gh-98966: Handle stdout=subprocess.STDOUT (GH-98967)Paulo Neves2024-03-261-0/+3
| | | | | | | Explicitly handle the case where stdout=STDOUT as otherwise the existing error handling gets confused and reports hard to understand errors. Signed-off-by: Paulo Neves <ptsneves@gmail.com>
* gh-90872: Fix subprocess.Popen.wait() for negative timeout (#116989)Victor Stinner2024-03-191-0/+2
| | | | | On Windows, subprocess.Popen.wait() no longer calls WaitForSingleObject() with a negative timeout: pass 0 ms if the timeout is negative.
* gh-116167: Allow disabling the GIL with `PYTHON_GIL=0` or `-X gil=0` (#116338)Brett Simmers2024-03-111-1/+1
| | | | | | | | | In free-threaded builds, running with `PYTHON_GIL=0` will now disable the GIL. Follow-up issues track work to re-enable the GIL when loading an incompatible extension, and to disable the GIL by default. In order to support re-enabling the GIL at runtime, all GIL-related data structures are initialized as usual, and disabling the GIL simply sets a flag that causes `take_gil()` and `drop_gil()` to return early.
* gh-104522: Fix OSError raised when run a subprocess (#114195)Serhiy Storchaka2024-01-181-3/+8
| | | | | | | Only set filename to cwd if it was caused by failed chdir(cwd). _fork_exec() now returns "noexec:chdir" for failed chdir(cwd). Co-authored-by: Robert O'Shea <PurityLake@users.noreply.github.com>
* gh-113117: Support posix_spawn in subprocess.Popen with close_fds=True (#113118)Jakub Kulík2023-12-171-3/+8
| | | | | | | | Add support for `os.POSIX_SPAWN_CLOSEFROM` and `posix_spawn_file_actions_addclosefrom_np` and have the `subprocess` module use them when available. This means `posix_spawn` can now be used in the default `close_fds=True` situation on many platforms. Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* gh-113119 fix environment handling in subprocess.Popen when posix_spawn is ↵Jakub Kulík2023-12-171-3/+0
| | | | | | | used (#113120) * Allow posix_spawn to inherit environment form parent environ variable. With this change, posix_spawn call can behave similarly to execv with regards to environments when used in subprocess functions.
* gh-112736: Refactor del-safe symbol handling in subprocess (#112738)Russell Keith-Magee2023-12-051-24/+24
| | | | | Refactor delete-safe symbol handling in subprocess. Only module globals are force-cleared during interpreter finalization, using a class reference instead of individually listing the constants everywhere is simpler.
* gh-106723: forward -Xfrozen_modules option to spawned process interpreters ↵Felipe A. Hernandez2023-07-281-1/+1
| | | | | | (#106724) Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-87474: Fix file descriptor leaks in subprocess.Popen (#96351)cptpcrd2023-05-161-130/+163
| | | | | | | This fixes several ways file descriptors could be leaked from `subprocess.Popen` constructor during error conditions by opening them later and using a context manager "fds to close" registration scheme to ensure they get closed before returning. --------- Co-authored-by: Gregory P. Smith [Google] <greg@krypto.org>
* gh-101283: Fix use of unbound variable (GH-101712)Steve Dower2023-02-081-0/+2
|
* gh-101283: Improved fallback logic for subprocess with shell=True on Windows ↵Oleg Iarygin2023-02-081-1/+15
| | | | (GH-101286)
* 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.