summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_subprocess.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-87744: fix waitpid race while calling send_signal in asyncio (#121126)Kumar Aditya2024-07-011-9/+26
| | | asyncio earlier relied on subprocess module to send signals to the process, this has some drawbacks one being that subprocess module unnecessarily calls waitpid on child processes and hence it races with asyncio implementation which internally uses child watchers. To mitigate this, now asyncio sends signals directly to the process without going through the subprocess on non windows systems. On Windows it fallbacks to subprocess module handling but on windows there are no child watchers so this issue doesn't exists altogether.
* gh-112800: Ignore PermissionError on SubprocessTransport.close() in asyncio ↵Allison Karlitskaya2023-12-241-1/+2
| | | | | | | | | | (#112803) In case the spawned process is setuid, we may not be able to send signals to it, in which case our .kill() call will raise PermissionError. Ignore that in order to avoid .close() raising an exception. Hopefully the process will exit as a result of receiving EOF on its stdin.
* GH-100133: fix `asyncio` subprocess losing `stderr` and `stdout` output ↵Kumar Aditya2022-12-211-3/+0
| | | | (#100154)
* GH-88050: fix race in closing subprocess pipe in asyncio (#97951)Kumar Aditya2022-10-061-1/+3
| | | Check for None when iterating over `self._pipes.values()`.
* gh-88050: Fix asyncio subprocess to kill process cleanly when process is ↵Kumar Aditya2022-10-051-6/+7
| | | | blocked (#32073)
* bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)Yury Selivanov2019-05-271-1/+3
| | | | | | | | | | | | | | | This will address the common mistake many asyncio users make: an "except Exception" clause breaking Tasks cancellation. In addition to this change, we stop inheriting asyncio.TimeoutError and asyncio.InvalidStateError from their concurrent.futures.* counterparts. There's no point for these exceptions to share the inheritance chain. In 3.9 we'll focus on implementing supervisors and cancel scopes, which should allow better handling of all exceptions, including SystemExit and KeyboardInterrupt
* asyncio: __del__() keep reference to warnings.warn (GH-11491)Victor Stinner2019-01-101-3/+2
| | | | | | | | | | | | | | | * asyncio: __del__() keep reference to warnings.warn The __del__() methods of asyncio classes now keep a strong reference to the warnings.warn() to be able to display the ResourceWarning warning in more cases. Ensure that the function remains available if instances are destroyed late during Python shutdown (while module symbols are cleared). * Rename warn parameter to _warn "_warn" name is a hint that it's not the regular warnings.warn() function.
* bpo-32262: Fix typo in f-string (GH-7016)Christian Heimes2018-05-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix typo from commit 6370f345e1d5829e1fba59cd695c8b82c5a8c620 Signed-off-by: Christian Heimes <christian@python.org> <!-- Thanks for your contribution! Please read this comment in its entirety. It's quite important. # Pull Request title It should be in the following format: ``` bpo-NNNN: Summary of the changes made ``` Where: bpo-NNNN refers to the issue number in the https://bugs.python.org. Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue. # Backport Pull Request title If this is a backport PR (PR made against branches other than `master`), please ensure that the PR title is in the following format: ``` [X.Y] <title from the original PR> (GH-NNNN) ``` Where: [X.Y] is the branch name, e.g. [3.6]. GH-NNNN refers to the PR number from `master`. --> <!-- issue-number: bpo-32262 --> https://bugs.python.org/issue32262 <!-- /issue-number -->
* bpo-32262: Fix codestyle; use f-strings formatting where necessary. (#4775)Yury Selivanov2017-12-101-18/+17
|
* bpo-32193: Convert asyncio to async/await usage (#4753)Andrew Svetlov2017-12-081-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Convert asyncio/tasks.py to async/await * Convert asyncio/queues.py to async/await * Convert asyncio/test_utils.py to async/await * Convert asyncio/base_subprocess.py to async/await * Convert asyncio/subprocess.py to async/await * Convert asyncio/streams.py to async/await * Fix comments * Convert asyncio/locks.py to async/await * Convert asyncio.sleep to async def * Add a comment * Add missing news * Convert stubs from AbstrctEventLoop to async functions * Convert subprocess_shell/subprocess_exec * Convert connect_read_pipe/connect_write_pip to async/await syntax * Convert create_datagram_endpoint * Convert create_unix_server/create_unix_connection * Get rid of old style coroutines in unix_events.py * Convert selector_events.py to async/await * Convert wait_closed and create_connection * Drop redundant line * Convert base_events.py * Code cleanup * Drop redundant comments * Fix indentation * Add explicit tests for compatibility between old and new coroutines * Convert windows event loop to use async/await * Fix double awaiting of async function * Convert asyncio/locks.py * Improve docstring * Convert tests to async/await * Convert more tests * Convert more tests * Convert more tests * Convert tests * Improve test
* bpo-29617: Remove Python 3.3 support from asyncio (GH-232)INADA Naoki2017-04-251-10/+5
|
* Misc asyncio improvements from upstream (merge 3.5->3.6)Guido van Rossum2016-09-301-1/+0
|\
| * Misc asyncio improvements from upstreamGuido van Rossum2016-09-301-1/+0
| |
* | Merge 3.5 (asyncio)Yury Selivanov2016-09-121-0/+6
|\ \ | |/
| * asyncio: Add set_protocol / get_protocol methods to TransportsYury Selivanov2016-09-121-0/+6
| |
* | Merge 3.5 (issue #26741)Victor Stinner2016-05-201-0/+4
|\ \ | |/
| * asyncio: fix ResourceWarning related to subprocessesVictor Stinner2016-05-201-0/+4
| | | | | | | | | | | | Issue #26741: asyncio: BaseSubprocessTransport._process_exited() now copies the return code from the child watched to the returncode attribute of the Popen object. On Python 3.6, it is required to avoid a ResourceWarning.
* | Merge 3.5 (Issue #27041)Yury Selivanov2016-05-161-1/+1
|\ \ | |/
| * Issue #27041: asyncio: Add loop.create_future methodYury Selivanov2016-05-161-1/+1
| |
* | Add a source parameter to warnings.warn()Victor Stinner2016-03-221-1/+2
|/ | | | | | | | Issue #26604: * Add a new optional source parameter to _warnings.warn() and warnings.warn() * Modify asyncore, asyncio and _pyio modules to set the source parameter when logging a ResourceWarning warning
* asyncio: Add Transport.is_closing()Yury Selivanov2015-11-161-0/+3
| | | | See https://github.com/python/asyncio/pull/291 for details.
* asyncio: Sync with upstream (compat module)Yury Selivanov2015-08-041-2/+2
|
* Fix ResourceWarning in asyncio.BaseSubprocessTransportVictor Stinner2015-07-311-2/+7
| | | | | | | Issue #24763: Fix resource warnings when asyncio.BaseSubprocessTransport constructor fails, if subprocess.Popen raises an exception for example. Patch written by Martin Richard, test written by me.
* Issue #23456: Add missing @coroutine decorators in asyncioVictor Stinner2015-03-181-0/+1
|
* asyncio: Fix repr(BaseSubprocessTransport) if it didn't start yetVictor Stinner2015-03-101-2/+5
| | | | | Replace "running" with "not started" and don't show the pid if the subprocess didn't start yet.
* Issue #23537: Remove 2 unused private methods of asyncio.BaseSubprocessTransportVictor Stinner2015-02-271-6/+0
| | | | Methods only raise NotImplementedError and are never used.
* asyncio: BaseSubprocessTransport: repr() mentions when the child process isVictor Stinner2015-02-171-0/+2
| | | | running
* asyncio: BaseSubprocessTransport.close() doesn't try to kill the process if itVictor Stinner2015-02-101-1/+6
| | | | already finished
* Issue #23347, asyncio: send_signal(), terminate(), kill() don't check if theVictor Stinner2015-01-301-4/+3
| | | | | | | transport was closed. The check broken a Tulip example and this limitation is arbitrary. Check if _proc is None should be enough. Enhance also close(): do nothing when called the second time.
* Issue #23347, asyncio: Make BaseSubprocessTransport.wait() privateVictor Stinner2015-01-291-1/+1
|
* asyncio: sync with TulipVictor Stinner2015-01-291-43/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Issue #23347: send_signal(), kill() and terminate() methods of BaseSubprocessTransport now check if the transport was closed and if the process exited. Issue #23347: Refactor creation of subprocess transports. Changes on BaseSubprocessTransport: * Add a wait() method to wait until the child process exit * The constructor now accepts an optional waiter parameter. The _post_init() coroutine must not be called explicitly anymore. It makes subprocess transports closer to other transports, and it gives more freedom if we want later to change completly how subprocess transports are created. * close() now kills the process instead of kindly terminate it: the child process may ignore SIGTERM and continue to run. Call explicitly terminate() and wait() if you want to kindly terminate the child process. * close() now logs a warning in debug mode if the process is still running and needs to be killed * _make_subprocess_transport() is now fully asynchronous again: if the creation of the transport failed, wait asynchronously for the process eixt. Before the wait was synchronous. This change requires close() to *kill*, and not terminate, the child process. * Remove the _kill_wait() method, replaced with a more agressive close() method. It fixes _make_subprocess_transport() on error. BaseSubprocessTransport.close() calls the close() method of pipe transports, whereas _kill_wait() closed directly pipes of the subprocess.Popen object without unregistering file descriptors from the selector (which caused severe bugs). These changes simplifies the code of subprocess.py.
* Issue #23243, asyncio: Emit a ResourceWarning when an event loop or a transportVictor Stinner2015-01-291-1/+18
| | | | is not explicitly closed. Close also explicitly transports in test_sslproto.
* asyncio: BaseSubprocessTransport._kill_wait() now also call close()Victor Stinner2015-01-291-0/+3
| | | | close() closes pipes, which is not None yet by _kill_wait().
* asyncio: sync with TulipVictor Stinner2015-01-141-1/+3
| | | | | | | | | | | | | | | | | | | | | | | * PipeHandle now uses None instead of -1 for a closed handle * Sort imports in windows_utils. * Fix test_events on Python older than 3.5. Skip SSL tests on the ProactorEventLoop if ssl.MemoryIO is missing * Fix BaseEventLoop._create_connection_transport(). Close the transport if the creation of the transport (if the waiter) gets an exception. * _ProactorBasePipeTransport now sets _sock to None when the transport is closed. * Fix BaseSubprocessTransport.close(). Ignore pipes for which the protocol is not set yet (still equal to None). * TestLoop.close() now calls the close() method of the parent class (BaseEventLoop). * Cleanup BaseSelectorEventLoop: create the protocol on a separated line for readability and ease debugging. * Fix BaseSubprocessTransport._kill_wait(). Set the _returncode attribute, so close() doesn't try to terminate the process. * Tests: explicitly close event loops and transports * UNIX pipe transports: add closed/closing in repr(). Add "closed" or "closing" state in the __repr__() method of _UnixReadPipeTransport and _UnixWritePipeTransport classes.
* Python issue #23173: sync with TulipVictor Stinner2015-01-141-24/+53
| | | | | | | | * If an exception is raised during the creation of a subprocess, kill the subprocess (close pipes, kill and read the return status). Log an error in such case. * Fix SubprocessStreamProtocol.connection_made() to handle cancelled waiter. Add unit test cancelling subprocess methods.
* Issue #23209: Break some reference cycles in asyncio. Patch written by MartinVictor Stinner2015-01-091-0/+1
| | | | Richard.
* asyncio: sync with TulipVictor Stinner2014-12-181-1/+1
| | | | | | | | | | | | | | | | * Fix a race condition in BaseSubprocessTransport._try_finish(). If the process exited before the _post_init() method was called, scheduling the call to _call_connection_lost() with call_soon() is wrong: connection_made() must be called before connection_lost(). Reuse the BaseSubprocessTransport._call() method to schedule the call to _call_connection_lost() to ensure that connection_made() and connection_lost() are called in the correct order. * Add repr(PipeHandle) * Fix typo
* asyncio: sync with TulipVictor Stinner2014-07-141-1/+39
| | | | | | | | | | | | | | | | | | | | * Tulip issue #184: Log subprocess events in debug mode - Log stdin, stdout and stderr transports and protocols - Log process identifier (pid) - Log connection of pipes - Log process exit - Log Process.communicate() tasks: feed stdin, read stdout and stderr - Add __repr__() method to many classes related to subprocesses * Add BaseSubprocessTransport._pid attribute. Store the pid so it is still accessible after the process exited. It's more convinient for debug. * create_connection(): add the socket in the "connected to" debug log * Clean up some docstrings and comments. Remove unused unimplemented _read_from_self().
* asyncio: sync with Tulip, add a new asyncio.coroutines moduleVictor Stinner2014-06-281-2/+2
|
* Issue #20400: Merge Tulip into Python: add the new asyncio.subprocess moduleVictor Stinner2014-02-011-14/+9
| | | | | | | | | | | | | | | | | | | | * Add a new asyncio.subprocess module * Add new create_subprocess_exec() and create_subprocess_shell() functions * The new asyncio.subprocess.SubprocessStreamProtocol creates stream readers for stdout and stderr and a stream writer for stdin. * The new asyncio.subprocess.Process class offers an API close to the subprocess.Popen class: - pid, returncode, stdin, stdout and stderr attributes - communicate(), wait(), send_signal(), terminate() and kill() methods * Remove STDIN (0), STDOUT (1) and STDERR (2) constants from base_subprocess and unix_events, to not be confused with the symbols with the same name of subprocess and asyncio.subprocess modules * _ProactorBasePipeTransport.get_write_buffer_size() now counts also the size of the pending write * _ProactorBaseWritePipeTransport._loop_writing() may now pause the protocol if the write buffer size is greater than the high water mark (64 KB by default)
* asyncio: Pass through pause/resume from subprocess pipe proto to subprocess ↵Guido van Rossum2014-01-291-2/+5
| | | | proto. Also kill dummy eof_received().
* asyncio: Get rid of _try_connected().Victor Stinner2014-01-291-18/+14
|
* Merge latest Tulip into asyncioAndrew Svetlov2014-01-261-1/+0
|
* asyncio: Add new file (forgotten).Guido van Rossum2013-10-301-0/+166