summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.13] gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests ↵Miss Islington (bot)2024-05-161-5/+2
| | | | | | | (GH-119065) (GH-119087) (cherry picked from commit 0152dc4ff5534fa2948b95262e70ff6b202b9b99) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-98966: Handle stdout=subprocess.STDOUT (GH-98967)Paulo Neves2024-03-261-0/+7
| | | | | | | 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-113964: Don't prevent new threads until all non-daemon threads exit (#116677)Sam Gross2024-03-191-6/+7
| | | | | | | | | | Starting in Python 3.12, we prevented calling fork() and starting new threads during interpreter finalization (shutdown). This has led to a number of regressions and flaky tests. We should not prevent starting new threads (or `fork()`) until all non-daemon threads exit and finalization starts in earnest. This changes the checks to use `_PyInterpreterState_GetFinalizing(interp)`, which is set immediately before terminating non-daemon threads.
* gh-90872: Fix subprocess.Popen.wait() for negative timeout (#116989)Victor Stinner2024-03-191-0/+16
| | | | | On Windows, subprocess.Popen.wait() no longer calls WaitForSingleObject() with a negative timeout: pass 0 ms if the timeout is negative.
* gh-104522: Fix test_subprocess failure when build Python in the root home ↵Serhiy Storchaka2024-01-181-8/+7
| | | | | | | | | directory (GH-114236) * gh-104522: Fix test_subprocess failure when build Python in the root home directory EPERM is raised when setreuid() fails. EACCES is set in execve() when the test user has not access to sys.executable.
* gh-104522: Fix OSError raised when run a subprocess (#114195)Serhiy Storchaka2024-01-181-5/+7
| | | | | | | 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-87868: Skip `test_one_environment_variable` in `test_subprocess` when the ↵AN Long2024-01-101-3/+12
| | | | | | | | | | | platform or build cannot do that (#113867) * improve the assert for test_one_environment_variable * skip some test in test_subprocess when python is configured with shared * also skip the test if AddressSanitizer is enabled --------- Co-authored-by: Steve Dower <steve.dower@microsoft.com>
* gh-87868: Sort and remove duplicates in getenvironment() (GH-102731)AN Long2024-01-091-0/+37
| | | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-113117: Support posix_spawn in subprocess.Popen with close_fds=True (#113118)Jakub Kulík2023-12-171-0/+5
| | | | | | | | 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-112334: Regression test that vfork is used when expected. (#112734)Gregory P. Smith2023-12-091-15/+83
| | | | | | | | | Regression test that vfork is used when expected by subprocess. This is written integration test style, it uses strace if it is present and appears to work to find out what system call actually gets used in different scenarios. Test coverage is added for the default behavior and that of each of the specific arguments that must disable the use of vfork. obviously not an entire test matrix, but it covers the most important aspects. If there are ever issues with this test being flaky or failing on new platforms, rather than try and adapt it for all possible platforms, feel free to narrow the range it gets tested on when appropriate. That is not likely to reduce coverage.
* gh-112334: Restore subprocess's use of `vfork()` & fix `extra_groups=[]` ↵Gregory P. Smith2023-12-041-21/+17
| | | | | | | | | | | | | | | | | | | | | behavior (#112617) Restore `subprocess`'s intended use of `vfork()` by default for performance on Linux; also fixes the behavior of `extra_groups=[]` which was unintentionally broken in 3.12.0: Fixed a performance regression in 3.12's :mod:`subprocess` on Linux where it would no longer use the fast-path ``vfork()`` system call when it could have due to a logic bug, instead falling back to the safe but slower ``fork()``. Also fixed a security bug introduced in 3.12.0. If a value of ``extra_groups=[]`` was passed to :mod:`subprocess.Popen` or related APIs, the underlying ``setgroups(0, NULL)`` system call to clear the groups list would not be made in the child process prior to ``exec()``. The security issue was identified via code inspection in the process of fixing the first bug. Thanks to @vain for the detailed report and analysis in the initial bug on Github. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-67224: Show source lines in tracebacks when using the -c option when ↵Pablo Galindo Salgado2023-10-261-2/+2
| | | | running Python (#111200)
* gh-110184: Fix subprocess test_pipesize_default() (#110465)Victor Stinner2023-10-061-18/+23
| | | | | For proc.stdin, get the size of the read end of the test pipe. Use subprocess context manager ("with proc:").
* gh-108416: Mark slow but not CPU bound test methods with ↵Serhiy Storchaka2023-09-051-0/+2
| | | | requires_resource('walltime') (GH-108480)
* gh-108416: Mark slow test methods with @requires_resource('cpu') (GH-108421)Serhiy Storchaka2023-09-021-0/+1
| | | | Only mark tests which spend significant system or user time, by itself or in subprocesses.
* gh-105436: Ignore unrelated errors when checking empty env (GH-105742)Steve Dower2023-06-131-3/+4
|
* gh-105436: The environment block should end with two null wchar_t values ↵Dora2032023-06-121-0/+7
| | | | (GH-105495)
* gh-104690 Disallow thread creation and fork at interpreter finalization ↵chgnrdv2023-06-041-0/+19
| | | | | | | | | | | | | | | | | (#104826) Disallow thread creation and fork at interpreter finalization. in the following functions, check if interpreter is finalizing and raise `RuntimeError` with appropriate message: * `_thread.start_new_thread` and thus `threading` * `posix.fork` * `posix.fork1` * `posix.forkpty` * `_posixsubprocess.fork_exec` when a `preexec_fn=` is supplied. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-104472: Skip `test_subprocess.ProcessTestCase.test_empty_env` if ASAN is ↵chgnrdv2023-05-191-0/+3
| | | | | enabled (#104667) Skip test_subprocess.ProcessTestCase.test_empty_env if ASAN is enabled.
* gh-95672 skip fcntl when pipesize is smaller than pagesize (gh-102163)Hyunkyun Moon2023-03-011-1/+2
|
* gh-95672 fix typo SkitTest to SkipTest (gh-102119)Hyunkyun Moon2023-02-211-1/+1
| | | Co-authored-by: HyunKyun Moon <hyunkyun.moon@linecorp.com>
* gh-100005: Skip test_script_as_dev_fd() on FreeBSD (#100006)Victor Stinner2022-12-051-1/+1
| | | | On FreeBSD, skip test_script_as_dev_fd() of test_cmd_line_script if fdescfs is not mounted (at /dev/fd).
* gh-60203: Always pass True/False as boolean arguments in tests (GH-99983)Serhiy Storchaka2022-12-041-1/+1
| | | Unless we explicitly test non-bool values.
* gh-97825: fix AttributeError when calling ↵andrei kulakov2022-10-051-0/+6
| | | | | subprocess.check_output(input=None) with encoding or errors args (#97826) * fix AttributeError, add unit test
* gh-82616: Add process_group support to subprocess.Popen (#23930)Gregory P. Smith2022-05-051-4/+22
| | | | | | | | 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: Use shell=True in test_subprocess.test_encoding_warning (GH-92090)Dennis Sweeney2022-05-011-6/+5
|
* gh-91954: Emit EncodingWarning from locale and subprocess (GH-91977)Inada Naoki2022-04-301-0/+14
| | | locale.getpreferredencoding() and subprocess.Popen() emit EncodingWarning
* gh-91401: Add a failsafe way to disable vfork. (#91490)Gregory P. Smith2022-04-251-2/+18
| | | | | | | | | | | | | | 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-5/+5
|
* bpo-40280: Skip subprocess-based tests on wasm32-emscripten (GH-30615)Christian Heimes2022-01-251-0/+3
|
* bpo-40497: Fix handling of check in subprocess.check_output() (GH-19897)Rémi Lapeyre2021-09-201-0/+8
| | | | Co-authored-by: Tal Einat <taleinat@gmail.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005)Serhiy Storchaka2021-08-291-0/+1
|
* bpo-43826: Fix resource warning due to unclosed objects. (GH-25381)Karthikeyan Singaravelan2021-08-241-0/+5
|
* bpo-28254: Cleanup test_subprocess.test_preexec_gc_module_failure() (GH-25709)Victor Stinner2021-04-291-4/+0
| | | Saving/restoring gc.disable and gc.isenabled is no longer needed.
* bpo-28254: _posixsubprocess uses PyGC_Enable/PyGC_Disable (GH-25693)Victor Stinner2021-04-281-12/+0
|
* bpo-43776: Remove list call from args in Popen repr (GH-25338)M. Kocher2021-04-281-22/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-42388: Fix subprocess.check_output input=None when text=True (GH-23467)Gregory P. Smith2020-12-251-0/+22
| | | | | | | | | | 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-0/+13
| | | | | | | 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-42146: Fix memory leak in subprocess.Popen() in case of uid/gid overflow ↵Alexey Izbyshev2020-10-261-0/+13
| | | | | | | | | | | (GH-22966) Fix memory leak in subprocess.Popen() in case of uid/gid overflow Also add a test that would catch this leak with `--huntrleaks`. Alas, the test for `extra_groups` also exposes an inconsistency in our error reporting: we use a custom ValueError for `extra_groups`, but propagate OverflowError for `user` and `group`.
* bpo-41586: Attempt to make the pipesize tests more robust. (GH-22839)Gregory P. Smith2020-10-211-34/+55
| | | | Several buildbots are failing on these, likely due to an inability to set the pipe size to the desired test value.
* bpo-41586: Add pipesize parameter to subprocess & F_GETPIPE_SZ and ↵Ruben Vorderman2020-10-191-1/+46
| | | | | | | | | | | | | | | | | 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-41385: Fix test_executable_without_cwd on Windows (GH-21608)Serhiy Storchaka2020-07-261-2/+4
|
* bpo-40275: Use new test.support helper submodules in tests (GH-21169)Hai Shi2020-06-301-10/+14
|
* bpo-39481: Implementation for PEP 585 (#18239)Guido van Rossum2020-04-071-2/+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 test.support.wait_process() (GH-19254)Victor Stinner2020-03-311-8/+3
| | | | | | | | | Moreover, the following tests now check the child process exit code: * test_os.PtyTests * test_mailbox.test_lock_conflict() * test_tempfile.test_process_awareness() * test_uuid.testIssue8621() * multiprocessing resource tracker tests
* bpo-22490: Remove __PYVENV_LAUNCHER__ from environment during launch (GH-9516)Ronald Oussoren2020-03-221-1/+0
| | | | | | | | | | | | | | | | | | | | | * bpo-22490: Remove "__PYVENV_LAUNCHER__" from the shell environment on macOS This changeset removes the environment varialbe "__PYVENV_LAUNCHER__" during interpreter launch as it is only needed to communicate between the stub executable in framework installs and the actual interpreter. Leaving the environment variable present may lead to misbehaviour when launching other scripts. * Actually commit the changes for issue 22490... * Correct typo Co-Authored-By: Nicola Soranzo <nicola.soranzo@gmail.com> * Run make patchcheck Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> Co-authored-by: Nicola Soranzo <nicola.soranzo@gmail.com>
* bpo-39855: Fix test_subprocess if nobody user doesn't exist (GH-18781)Victor Stinner2020-03-051-2/+7
| | | | | test_subprocess.test_user() now skips the test on an user name if the user name doesn't exist. For example, skip the test if the user "nobody" doesn't exist on Linux.
* bpo-35182: fix communicate() crash after child closes its pipes (GH-17020) ↵Alex Rebert2020-01-221-0/+11
| | | | | | | | | (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-0/+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/+3
|