summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.7] bpo-22490: Remove __PYVENV_LAUNCHER__ from environment during launch ↵Jason R. Coombs2020-03-221-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-9516) (GH-19111) * 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>. (cherry picked from commit 044cf94f610e831464a69a8e713dad89878824ce) Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com> Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
* [3.7] bpo-35182: fix communicate() crash after child closes its pipes ↵Alex Rebert2020-01-231-0/+11
| | | | | | | | | | | | | | | | | | | | | (GH-18117) (GH-18151) 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>. (cherry picked from commit d3ae95e1e945ed20297e1c38ba43a18b7a868ab6) Co-authored-by: Alex Rebert <alex@forallsecure.com> https://bugs.python.org/issue35182 Automerge-Triggered-By: @gpshead
* bpo-37424: Avoid a hang in subprocess.run timeout output capture (GH-14490)Miss Islington (bot)2019-09-111-0/+21
| | | | | | | | | | 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. (cherry picked from commit 580d2782f70f8e0bed7ec20abb03d740cb83b5da) Co-authored-by: Gregory P. Smith <greg@krypto.org>
* bpo-37380: subprocess: don't use _active on win (GH-14360) (GH-15706)Miss Islington (bot)2019-09-061-9/+25
| | | | | | | | | | | | | | | | | | | | | | 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/issue37380GH-msg346333 [2] https://bugs.python.org/issue36067GH-msg336262 Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai> (cherry picked from commit 042821ae3cf537e01963c9ec85d1a454d921e826) Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com>
* Revert "Remove unused imports in tests (GH-14518) (GH-14522)" (GH-14555)Victor Stinner2019-07-021-1/+8
| | | This reverts commit e34b5f4d6483187969d5149c801d056b72ef2ddb.
* Remove unused imports in tests (GH-14518) (GH-14522)Victor Stinner2019-07-011-8/+1
| | | (cherry picked from commit 8f4ef3b019ce380022018587571b0f970e668de3)
* bpo-32270: Don't close stdin/out/err in pass_fds (GH-6242) (GH-9148)Miss Islington (bot)2018-09-111-0/+30
| | | | | | | | | | | | | | | | | When subprocess.Popen() stdin= stdout= or stderr= handles are specified and appear in pass_fds=, don't close the original fds after dup'ing them. This implementation and unittest primarily came from @izbyshev (see the PR) See also https://github.com/izbyshev/cpython/commit/b89b52f28490b69142d5c061604b3a3989cec66c This also removes the old manual p2cread, c2pwrite, and errwrite closing logic as inheritable flags and _close_open_fds takes care of that properly today without special treatment. This code is within child_exec() where it is the only thread so there is no race condition between the dup and _Py_set_inheritable_async_safe call. (cherry picked from commit ce34410b8b67f49d8275c05d51b3ead50cf97f48) Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google]
* Remove AIX workaround test_subprocess (GH-8939)Miss Islington (bot)2018-08-271-8/+2
| | | | | | | An old apparent AIX behavior workaround in test_subprocess's test_undecodable_env is no longer needed. (cherry picked from commit 89d79b1449750b14ded0149dcdd1e39247f2c65d) Co-authored-by: Michael Felt <aixtools@users.noreply.github.com>
* bpo-34044: subprocess.Popen copies startupinfo (GH-8090) (GH-8121)Victor Stinner2018-07-051-0/+27
| | | | | | | | | | | | subprocess.Popen now copies the startupinfo argument to leave it unchanged: it will modify the copy, so that the same STARTUPINFO object can be used multiple times. Add subprocess.STARTUPINFO._copy() private method. Python 3.7 backport from master makes the copy() private: renamed to _copy(). (cherry picked from commit 483422f57e5d8c8bf8820fec29fc9b96bb15d4ef)
* Improve the subprocess restore_signals=True test. (GH-7414) (GH-7437)Miss Islington (bot)2018-06-071-6/+22
| | | | | | It wasn't testing functionality. Now it is (on Linux anyways). (cherry picked from commit 5f3d04fa4e9b3c3b0e4807f8516de9365bfed467) Co-authored-by: Gregory P. Smith <greg@krypto.org>
* bpo-32844: Fix a subprocess misredirection of a low fd (GH5689)Miss Islington (bot)2018-03-261-0/+50
| | | | | | | | | | | | | bpo-32844: subprocess: Fix a potential misredirection of a low fd to stderr. When redirecting, subprocess attempts to achieve the following state: each fd to be redirected to is less than or equal to the fd it is redirected from, which is necessary because redirection occurs in the ascending order of destination descriptors. It fails to do so in a couple of corner cases, for example, if 1 is redirected to 2 and 0 is closed in the parent. (cherry picked from commit 0e7144b064a19493a146af94175a087b3888c37b) Co-authored-by: Alexey Izbyshev <izbyshev@users.noreply.github.com>
* bpo-32964: Reuse a testing implementation of the path protocol in tests. ↵Miss Islington (bot)2018-03-021-6/+2
| | | | | | | (GH-5930) (cherry picked from commit b21d155f57d284aecf9092a9bd24258293965c2f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* Revert "bpo-31961: subprocess now accepts path-like args (GH-4329)" ↵Miss Islington (bot)2018-02-271-31/+0
| | | | | | | | | | (GH-5912) (GH-5931) * Revert "bpo-31961: subprocess now accepts path-like args (GH-4329)" This reverts commit dd42cb71f2cb02f3a32f016137b12a146bc0d0e2. (cherry picked from commit be50a7b627d0aa37e08fa8e2d5568891f19903ce) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-30121: Fix test_subprocess for Windows Debug builds (GH-5758)Miss Islington (bot)2018-02-191-1/+1
| | | | | (cherry picked from commit 5537646bfacec463b450871dde31cb06c44a0556) Co-authored-by: Zachary Ware <zachary.ware@gmail.com>
* bpo-31961: subprocess now accepts path-like args (GH-4329)Anders Lorentsen2018-01-301-0/+31
| | | Allow os.PathLike args in subprocess APIs.
* bpo-32102 Add "capture_output=True" to subprocess.run (GH-5149)Bo Bayles2018-01-301-0/+32
| | | | Add "capture_output=True" option to subprocess.run, this is equivalent to setting stdout=PIPE, stderr=PIPE but is much more readable.
* bpo-25942: make subprocess more graceful on ^C (GH-5026)Gregory P. Smith2018-01-301-0/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Do not allow receiving a SIGINT to cause the subprocess module to trigger an immediate SIGKILL of the child process. SIGINT is normally sent to all child processes by the OS at the same time already as was the established normal behavior in 2.7 and 3.2. This behavior change was introduced during the fix to https://bugs.python.org/issue12494 and is generally surprising to command line tool users who expect other tools launched in child processes to get their own SIGINT and do their own cleanup. In Python 3.3-3.6 subprocess.call and subprocess.run would immediately SIGKILL the child process upon receiving a SIGINT (which raises a KeyboardInterrupt). We now give the child a small amount of time to exit gracefully before resorting to a SIGKILL. This is also the case for subprocess.Popen.__exit__ which would previously block indefinitely waiting for the child to die. This was hidden from many users by virtue of subprocess.call and subprocess.run sending the signal immediately. Behavior change: subprocess.Popen.__exit__ will not block indefinitely when the exiting exception is a KeyboardInterrupt. This is done for user friendliness as people expect their ^C to actually happen. This could cause occasional orphaned Popen objects when not using `call` or `run` with a child process that hasn't exited. Refactoring involved: The Popen.wait method deals with the KeyboardInterrupt second chance, existing platform specific internals have been renamed to _wait(). Also fixes comment typos.
* bpo-32667: Fix tests when $PATH contains a file (#5322)Victor Stinner2018-01-251-8/+7
| | | | | Some tests failed when the PATH environment variable contained a path to an existing file. Fix tests to ignore also NotADirectoryError, not only FileNotFoundError and PermissionError.
* bpo-32369: test_subprocess: Fix pass_fds check in test_close_fds() (#4920)izbyshev2017-12-181-2/+2
| | | | | | | | | | The last part of test_close_fds() doesn't match its own comment. The following assertion always holds because fds_to_keep and open_fds are disjoint by construction. self.assertFalse(remaining_fds & fds_to_keep & open_fds, "Some fds not in pass_fds were left open") Fix the code to match the message in the assertion.
* bpo-19764: Implemented support for subprocess.Popen(close_fds=True) on ↵Segev Finer2017-12-181-5/+61
| | | | | | | | | | | | | | | | | Windows (#1218) Even though Python marks any handles it opens as non-inheritable there is still a race when using `subprocess.Popen` since creating a process with redirected stdio requires temporarily creating inheritable handles. By implementing support for `subprocess.Popen(close_fds=True)` we fix this race. In order to implement this we use PROC_THREAD_ATTRIBUTE_HANDLE_LIST which is available since Windows Vista. Which allows to pass an explicit list of handles to inherit when creating a process. This commit also adds `STARTUPINFO.lpAttributeList["handle_list"]` which can be used to control PROC_THREAD_ATTRIBUTE_HANDLE_LIST directly.
* bpo-31756: subprocess.run should alias universal_newlines to text (#4049)andyclegg2017-10-231-35/+38
| | | | | | | | | Improve human friendliness of the Popen API: Add text=False as a keyword-only argument to subprocess.Popen along with a Popen attribute .text_mode and set this based on the encoding/errors/universal_newlines/text arguments. The universal_newlines parameter and attribute are maintained for backwards compatibility.
* bpo-31178: Mock os.waitpid() in test_subprocess (#3896)Victor Stinner2017-10-051-4/+8
| | | | | | Fix test_exception_errpipe_bad_data() and test_exception_errpipe_normal() of test_subprocess: mock os.waitpid() to avoid calling the real os.waitpid(0, 0) which is an unexpected side effect of the test.
* bpo-31471: Fix assertion failure in subprocess.Popen() on Windows, in case ↵Oren Milman2017-09-141-0/+9
| | | | env has a bad keys() method. (#3580)
* bpo-31370: Remove support for threads-less builds (#3385)Antoine Pitrou2017-09-071-7/+1
| | | | | | * Remove Setup.config * Always define WITH_THREAD for compatibility.
* bpo-31178: Avoid concatenating bytes with str in subprocess error (#3066)Ammar Askar2017-09-061-0/+47
| | | Avoid concatenating bytes with str in the typically rare subprocess error path (exec failed). Includes a mock based unittest to exercise the codepath.
* bpo-12383: Also ignore __PYVENV_LAUNCHER__ (#3278)Ned Deily2017-09-041-0/+1
| | | Used in macOS framework builds.
* Skip two tests not intended to pass on Windows. (#3202)Gregory P. Smith2017-08-251-0/+2
|
* bpo-22536: Set the filename in FileNotFoundError. (#3194)Gregory P. Smith2017-08-241-0/+10
| | | | Have the subprocess module set the filename in the FileNotFoundError exception raised on POSIX systems when the executable or cwd are missing.
* Add test_subprocess.test_nonexisting_with_pipes() (#3133)Victor Stinner2017-08-211-4/+47
| | | | bpo-30121: Test the Popen failure when Popen was created with pipes. Create also NONEXISTING_CMD variable in test_subprocess.py.
* bpo-30121: Fix debug assert in subprocess on Windows (#1224)Segev Finer2017-08-181-4/+5
| | | | | | | | | * bpo-30121: Fix debug assert in subprocess on Windows This is caused by closing HANDLEs using os.close which is for CRT file descriptors and not for HANDLEs. * bpo-30121: Suppress debug assertion in test_subprocess when ran directly
* bpo-31173: Rewrite WSTOPSIG test of test_subprocess (#3055)Victor Stinner2017-08-101-35/+22
| | | | | | | | | | | | | The current test_child_terminated_in_stopped_state() function test creates a child process which calls ptrace(PTRACE_TRACEME, 0, 0) and then crash (SIGSEGV). The problem is that calling os.waitpid() in the parent process is not enough to close the process: the child process remains alive and so the unit test leaks a child process in a strange state. Closing the child process requires non-trivial code, maybe platform specific. Remove the functional test and replaces it with an unit test which mocks os.waitpid() using a new _testcapi.W_STOPCODE() function to test the WIFSTOPPED() path.
* Spelling fixes (#2902)Ville Skyttä2017-08-031-4/+4
|
* bpo-31067: test_subprocess calls reap_children() (#2931)Victor Stinner2017-07-281-0/+2
| | | | test_subprocess now also calls reap_children() in tearDown(), not only on setUp().
* bpo-30764: test_subprocess uses SuppressCrashReport (#2405)Victor Stinner2017-06-261-19/+22
| | | | | bpo-30764, bpo-29335: test_child_terminated_in_stopped_state() of test_subprocess now uses support.SuppressCrashReport() to prevent the creation of a core dump on FreeBSD.
* bpo-30730: Prevent environment variables injection in subprocess on Windows. ↵Serhiy Storchaka2017-06-231-0/+40
| | | | | | (#2325) Prevent passing other invalid environment variables and command arguments.
* bpo-28180: Implementation for PEP 538 (#659)Nick Coghlan2017-06-111-1/+2
| | | | | | | | | | - new PYTHONCOERCECLOCALE config setting - coerces legacy C locale to C.UTF-8, C.utf8 or UTF-8 by default - always uses C.UTF-8 on Android - uses `surrogateescape` on stdin and stdout in the coercion target locales - configure option to disable locale coercion at build time - configure option to disable C locale warning at build time
* subprocess test_empty_env typo fix. (#1877)Gregory P. Smith2017-05-301-3/+3
|
* bpo-12383: Refactor subprocess test_empty_env (#1874)Gregory P. Smith2017-05-301-12/+20
| | | | | | | | | | | | Bugfix: This test wasn't being run because it was skipping based on the presence of Py_ENABLE_SHARED rather than its value. It is always present on POSIX systems but defaults to 0. Refactoring: Move the environment variables that can be ignored into a function. Parse the list from the child process and filter out the ones to exclude in the parent before checking that the rest is empty. Feature: Adds always present environment variables to ignore when running in a Gentoo sandbox so that the test can pass there.
* bpo-29335 - apply suggested test_subprocess simplifications from haypo and ↵Gregory P. Smith2017-05-231-9/+5
| | | | | Zach: (#1757) use faulthandler._sigsegv() and ctypes.util.find_library('c')
* bpo-30065: Fixed arguments validation in _posixsubprocess.fork_exec(). (#1110)Serhiy Storchaka2017-04-191-1/+12
|
* bpo-28624: Add a test that checks that cwd parameter of Popen() accepts ↵Sayan Chowdhury2017-02-261-0/+10
| | | | PathLike objects (#157)
* bpo-26128: Added __init__to subprocess.STARTUPINFO (#171)Subhendu Ghosh2017-02-251-0/+16
| | | | | | | The Windows-specific subprocess.STARTUPINFO class now accepts keyword-only arguments to its constructor to set the various data attributes. Patch by Subhendu Ghosh.
* Skip the test requiring ctypes if ctypes is unavailable.Gregory P. Smith2017-01-231-1/+6
|\ | | | | | | prevents http://buildbot.python.org/all/builders/x86%20Ubuntu%20Shared%203.x/builds/240/steps/test/logs/stdio
| * Skip the test requiring ctypes if ctypes is unavailable.Gregory P. Smith2017-01-231-1/+6
| |\ | | | | | | | | | prevents http://buildbot.python.org/all/builders/x86%20Ubuntu%20Shared%203.x/builds/240/steps/test/logs/stdio
| | * Skip the test requiring ctypes if ctypes is unavailable.Gregory P. Smith2017-01-231-1/+6
| | | | | | | | | | | | prevents http://buildbot.python.org/all/builders/x86%20Ubuntu%20Shared%203.x/builds/240/steps/test/logs/stdio
* | | typo fix, extra '.' on MacOS :)Gregory P. Smith2017-01-231-1/+1
|\ \ \ | |/ /
| * | typo fix, extra '.' on MacOS :)Gregory P. Smith2017-01-231-1/+1
| |\ \ | | |/
| | * typo fix, extra '.' :)Gregory P. Smith2017-01-231-1/+1
| | |
* | | Issue #29335: Fix subprocess.Popen.wait() when the child process hasGregory P. Smith2017-01-231-0/+41
|\ \ \ | |/ / | | | | | | exited to a stopped instead of terminated state (ex: when under ptrace).
| * | Issue #29335: Fix subprocess.Popen.wait() when the child process hasGregory P. Smith2017-01-231-0/+41
| |\ \ | | |/ | | | | | | exited to a stopped instead of terminated state (ex: when under ptrace).