summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* bpo-8110: Refactor platform detection in subprocess (GH-9053)Zachary Ware2018-09-101-55/+56
| | | | Check for functionality via imports rather than checking sys.platform specifically for Windows
* bpo-34044: subprocess.Popen copies startupinfo (GH-8090)Victor Stinner2018-07-051-0/+17
| | | | | | | 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() method.
* Revert "bpo-31961: subprocess now accepts path-like args (GH-4329)" (#5912)Serhiy Storchaka2018-02-271-10/+2
| | | | | | * Revert "bpo-31961: subprocess now accepts path-like args (GH-4329)" This reverts commit dd42cb71f2cb02f3a32f016137b12a146bc0d0e2.
* bpo-31961: subprocess now accepts path-like args (GH-4329)Anders Lorentsen2018-01-301-2/+10
| | | Allow os.PathLike args in subprocess APIs.
* bpo-32102 Add "capture_output=True" to subprocess.run (GH-5149)Bo Bayles2018-01-301-1/+9
| | | | 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-13/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-19764: Implemented support for subprocess.Popen(close_fds=True) on ↵Segev Finer2017-12-181-19/+46
| | | | | | | | | | | | | | | | | 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-29240: PEP 540: Add a new UTF-8 Mode (#855)Victor Stinner2017-12-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | * Add -X utf8 command line option, PYTHONUTF8 environment variable and a new sys.flags.utf8_mode flag. * If the LC_CTYPE locale is "C" at startup: enable automatically the UTF-8 mode. * Add _winapi.GetACP(). encodings._alias_mbcs() now calls _winapi.GetACP() to get the ANSI code page * locale.getpreferredencoding() now returns 'UTF-8' in the UTF-8 mode. As a side effect, open() now uses the UTF-8 encoding by default in this mode. * Py_DecodeLocale() and Py_EncodeLocale() now use the UTF-8 encoding in the UTF-8 Mode. * Update subprocess._args_from_interpreter_flags() to handle -X utf8 * Skip some tests relying on the current locale if the UTF-8 mode is enabled. * Add test_utf8mode.py. * _Py_DecodeUTF8_surrogateescape() gets a new optional parameter to return also the length (number of wide characters). * pymain_get_global_config() and pymain_set_global_config() now always copy flag values, rather than only copying if the new value is greater than the old value.
* bpo-32230: Set sys.warnoptions with -X dev (#4820)Victor Stinner2017-12-121-4/+14
| | | | | | | | | | | | | | Rather than supporting dev mode directly in the warnings module, this instead adjusts the initialisation code to add an extra 'default' entry to sys.warnoptions when dev mode is enabled. This ensures that dev mode behaves *exactly* as if `-Wdefault` had been passed on the command line, including in the way it interacts with `sys.warnoptions`, and with other command line flags like `-bb`. Fix also bpo-20361: have -b & -bb options take precedence over any other warnings options. Patch written by Nick Coghlan, with minor modifications of Victor Stinner.
* bpo-32089: Fix warnings filters in dev mode (#4482)Victor Stinner2017-11-211-6/+2
| | | | | | | | | | The developer mode (-X dev) now creates all default warnings filters to order filters in the correct order to always show ResourceWarning and make BytesWarning depend on the -b option. Write a functional test to make sure that ResourceWarning is logged twice at the same location in the developer mode. Add a new 'dev_mode' field to _PyCoreConfig.
* bpo-32094: Update subprocess for -X dev (#4480)Victor Stinner2017-11-201-1/+22
| | | | | | | | Modify subprocess._args_from_interpreter_flags() to handle -X dev option. Add also unit tests for test.support.args_from_interpreter_flags() and test.support.optim_args_from_interpreter_flags().
* bpo-31884 subprocess: add Windows constants for process priority (#4150)James2017-11-081-2/+12
|
* Fix miscellaneous typos (#4275)luzpaz2017-11-051-1/+1
|
* bpo-31756: subprocess.run should alias universal_newlines to text (#4049)andyclegg2017-10-231-26/+52
| | | | | | | | | 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.
* Update subprocess.communicate() docstring.Joel Schaerer2017-09-131-3/+3
| | | Explicitly state that communicate() closes stdin after writing input to it.
* bpo-22635: Update the getstatusoutput docstring. (#3435)Gregory P. Smith2017-09-071-7/+9
| | | | | To match the documentation updates already made. Also renames the local variable used within to match what it actually holds.
* bpo-31370: Remove support for threads-less builds (#3385)Antoine Pitrou2017-09-071-4/+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-3/+6
| | | Avoid concatenating bytes with str in the typically rare subprocess error path (exec failed). Includes a mock based unittest to exercise the codepath.
* bpo-22536: Set the filename in FileNotFoundError. (#3194)Gregory P. Smith2017-08-241-6/+6
| | | | Have the subprocess module set the filename in the FileNotFoundError exception raised on POSIX systems when the executable or cwd are missing.
* bpo-30121: Fix debug assert in subprocess on Windows (#1224)Segev Finer2017-08-181-1/+7
| | | | | | | | | * 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-30730: Prevent environment variables injection in subprocess on Windows. ↵Serhiy Storchaka2017-06-231-2/+6
| | | | | | (#2325) Prevent passing other invalid environment variables and command arguments.
* bpo-30418: Popen.communicate() always ignore EINVAL (#2002)Victor Stinner2017-06-081-6/+8
| | | | | On Windows, subprocess.Popen.communicate() now also ignore EINVAL on stdin.write() if the child process is still running but closed the pipe.
* bpo-30065: Fixed arguments validation in _posixsubprocess.fork_exec(). (#1110)Serhiy Storchaka2017-04-191-1/+2
|
* fix subprocess on Windows (#391)Benjamin Peterson2017-03-021-1/+1
|
* allow path-like objects to be cwd on windows (#389)Benjamin Peterson2017-03-021-1/+1
| | | #157 added the test, but it's currently (correctly) broken on windows.
* bpo-26128: Added __init__to subprocess.STARTUPINFO (#171)Subhendu Ghosh2017-02-251-5/+7
| | | | | | | The Windows-specific subprocess.STARTUPINFO class now accepts keyword-only arguments to its constructor to set the various data attributes. Patch by Subhendu Ghosh.
* Issue #29335: Fix subprocess.Popen.wait() when the child process hasGregory P. Smith2017-01-231-1/+4
|\ | | | | | | 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-1/+4
| |\ | | | | | | | | | 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-1/+4
| | | | | | | | | | | | exited to a stopped instead of terminated state (ex: when under ptrace).
* | | Merge 3.6Victor Stinner2017-01-061-3/+3
|\ \ \ | |/ /
| * | Fix subprocess.Popen.__del__() fox Python shutdownVictor Stinner2017-01-061-3/+3
| | | | | | | | | | | | | | | Issue #29174, #26741: subprocess.Popen.__del__() now keeps a strong reference to warnings.warn() function.
* | | Issue #16255: subrocess.Popen uses /system/bin/sh on Android as the shell,Xavier de Gaye2016-12-131-1/+4
| | | | | | | | | | | | instead of /bin/sh.
* | | Issue #20572: Remove the subprocess.Popen.wait endtime parameter.Gregory P. Smith2016-11-211-13/+4
|\ \ \ | |/ / | | | | | | It was deprecated in 3.4 and undocumented prior to that.
| * | Issue #20572: The subprocess.Popen.wait method's undocumented endtimeGregory P. Smith2016-11-211-2/+9
|/ / | | | | | | | | parameter now raises a DeprecationWarning. It was deprecated in 3.4. It was never documented prior to that.
* | Issue #26240: Merge subprocess doc string from 3.5 into 3.6Martin Panter2016-10-251-340/+81
|\ \ | |/
| * Issue #26240: Clean up the subprocess module doc stringMartin Panter2016-10-251-348/+79
| | | | | | | | Patch by Tim Mitchell.
* | Issue #6135: Adds encoding and errors parameters to subprocessSteve Dower2016-09-071-42/+45
| |
* | subprocess: enhance ResourceWarning messageVictor Stinner2016-06-141-3/+4
| | | | | | | | | | * Add the process identifier to the warning message * Add also a comment to explain the issue
* | merge from 3.5 - Fixes Issue #26373: subprocess.Popen.communicateGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)2016-06-041-5/+18
|\ \ | |/ | | | | | | now correctly ignores BrokenPipeError when the child process dies before .communicate() is called in more (all?) circumstances.
| * Fixes Issue #26373: subprocess.Popen.communicate now correctly ignoresGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)2016-06-041-5/+18
| | | | | | | | | | BrokenPipeError when the child process dies before .communicate() is called in more (all?) circumstances.
* | Issue #27167: Clarify the subprocess.CalledProcessError error message textGregory P. Smith ext:(%20%5BGoogle%20Inc.%5D)2016-06-031-4/+15
| | | | | | | | when the child process died due to a signal.