summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-133089: Use original timeout value for `TimeoutExpired` when the ↵Miss Islington (bot)2025-05-051-4/+10
| | | | | | | | | | func `subprocess.run` is called with a timeout (GH-133103) (#133418) gh-133089: Use original timeout value for `TimeoutExpired` when the func `subprocess.run` is called with a timeout (GH-133103) (cherry picked from commit 2bbcaedb75942389dacb51866948f40de5951c9c) Signed-off-by: Manjusaka <me@manjusaka.me> Co-authored-by: Nadeshiko Manju <me@manjusaka.me> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* [3.13] gh-129204: Add _PYTHON_SUBPROCESS_USE_POSIX_SPAWN environment knob ↵Miss Islington (bot)2025-04-071-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | (GH-132184) (#132191) gh-129204: Add _PYTHON_SUBPROCESS_USE_POSIX_SPAWN environment knob (GH-132184) * Add _PYTHON_SUBPROCESS_USE_POSIX_SPAWN environment knob Add support for disabling the use of `posix_spawn` via a variable in the process environment. While it was previously possible to toggle this by modifying the value of `subprocess._USE_POSIX_SPAWN`, this required either patching CPython or modifying it within the interpreter instance which is not always possible, such as when running applications or scripts not under a user's control. * fixup NEWS entry --------- (cherry picked from commit 4c5dcc6d8292d5142aff8401cb9b9d18b49c6c89) Signed-off-by: Vincent Fazio <vfazio@gmail.com> Co-authored-by: Vincent Fazio <vfazio@gmail.com>
* [3.13] gh-118761: Revert "Improve import time of `subprocess` (GH-129427)" ↵Miss Islington (bot)2025-02-161-14/+2
| | | | | | | | | | | | | | | | | | | | (GH-130201) (#130204) gh-118761: Revert "Improve import time of `subprocess` (GH-129427)" (GH-130201) * Revert "gh-118761: Improve import time of `subprocess` (GH-129427)" This reverts commit 49f24650e4541456872490ec2b59d6d186204891. Also known as f502c8f6a6db4be27c97a0e5466383d117859b7f in 3.13 (PR GH-129447) Also known as f65aa0d1bf7b636ab8f9d226429205854b24cd7a in 3.12 (PR GH-129448) This caused bugs in the `__del__` finalizer: https://github.com/python/cpython/issues/118761#issuecomment-2661504264 --------- (cherry picked from commit ae3064608935367c860182dc1b364631082ecdff) Co-authored-by: Gregory P. Smith <greg@krypto.org> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* [3.13] gh-118761: Improve import time of `subprocess` (GH-129427) (#129447)Miss Islington (bot)2025-01-291-2/+14
| | | | | | | | gh-118761: Improve import time of `subprocess` (GH-129427) * subprocess: lazy import signal and locale to improve module import time (cherry picked from commit 49f24650e4541456872490ec2b59d6d186204891) Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com>
* [3.13] gh-128342: Specify timeout unit in subprocess docstrings (GH-128343) ↵Miss Islington (bot)2024-12-301-3/+3
| | | | | | | | | | | (#128365) gh-128342: Specify timeout unit in subprocess docstrings (GH-128343) Specify timeout unit (seconds) in subprocess docstrings (cherry picked from commit dafe7a44630aa32bb411cceb45c7b7df725e3fe3) Co-authored-by: n-l-i <57808975+n-l-i@users.noreply.github.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* [3.13] GH-118844: Fix build failures when combining --disable-gil with ↵Miss Islington (bot)2024-05-131-1/+1
| | | | | | | --enable-experimental-jit (GH-118959) (cherry picked from commit 5b941e57c71d7d0ab983d81a169f892662cfe446) Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
* 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.