diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2022-10-15 23:09:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-15 23:09:30 (GMT) |
commit | 660f10248ba321e7783c07f3801991275e2aee1e (patch) | |
tree | 7c1c2ba0839fc2e653117e1d26af7810f3e28cdc /Lib/asyncio | |
parent | bb56dead336357153a0c3b8cc9d9d6856d2c5a03 (diff) | |
download | cpython-660f10248ba321e7783c07f3801991275e2aee1e.zip cpython-660f10248ba321e7783c07f3801991275e2aee1e.tar.gz cpython-660f10248ba321e7783c07f3801991275e2aee1e.tar.bz2 |
GH-94597: Deprecate child watcher getters and setters (#98215)
This is the next step for deprecating child watchers.
Until we've removed the API completely we have to use it, so this PR is mostly suppressing a lot of warnings when using the API internally.
Once the child watcher API is totally removed, the two child watcher implementations we actually use and need (Pidfd and Thread) will be turned into internal helpers.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/unix_events.py | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 9f9b03e..ea7010e 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -195,30 +195,32 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): async def _make_subprocess_transport(self, protocol, args, shell, stdin, stdout, stderr, bufsize, extra=None, **kwargs): - with events.get_child_watcher() as watcher: - if not watcher.is_active(): - # Check early. - # Raising exception before process creation - # prevents subprocess execution if the watcher - # is not ready to handle it. - raise RuntimeError("asyncio.get_child_watcher() is not activated, " - "subprocess support is not installed.") - waiter = self.create_future() - transp = _UnixSubprocessTransport(self, protocol, args, shell, - stdin, stdout, stderr, bufsize, - waiter=waiter, extra=extra, - **kwargs) - - watcher.add_child_handler(transp.get_pid(), - self._child_watcher_callback, transp) - try: - await waiter - except (SystemExit, KeyboardInterrupt): - raise - except BaseException: - transp.close() - await transp._wait() - raise + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + with events.get_child_watcher() as watcher: + if not watcher.is_active(): + # Check early. + # Raising exception before process creation + # prevents subprocess execution if the watcher + # is not ready to handle it. + raise RuntimeError("asyncio.get_child_watcher() is not activated, " + "subprocess support is not installed.") + waiter = self.create_future() + transp = _UnixSubprocessTransport(self, protocol, args, shell, + stdin, stdout, stderr, bufsize, + waiter=waiter, extra=extra, + **kwargs) + + watcher.add_child_handler(transp.get_pid(), + self._child_watcher_callback, transp) + try: + await waiter + except (SystemExit, KeyboardInterrupt): + raise + except BaseException: + transp.close() + await transp._wait() + raise return transp @@ -1469,6 +1471,9 @@ class _UnixDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy): if self._watcher is None: self._init_watcher() + warnings._deprecated("get_child_watcher", + "{name!r} is deprecated as of Python 3.12 and will be " + "removed in Python {remove}.", remove=(3, 14)) return self._watcher def set_child_watcher(self, watcher): @@ -1480,6 +1485,9 @@ class _UnixDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy): self._watcher.close() self._watcher = watcher + warnings._deprecated("set_child_watcher", + "{name!r} is deprecated as of Python 3.12 and will be " + "removed in Python {remove}.", remove=(3, 14)) SelectorEventLoop = _UnixSelectorEventLoop |