summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-11-12 12:47:53 +0530
committerGitHub <noreply@github.com>2022-11-11 23:17:53 -0800
commitaa874326d86734606a1930e7f48e2ee204cae0b6 (patch)
treee0f68cc2b753c4b5f43ec278ed5e95650df88b9e
parente02cc6d42aee1f0a9ee629f76576eee478224d9d (diff)
downloadcpython-git-aa874326d86734606a1930e7f48e2ee204cae0b6.tar.gz
GH-94597: add deprecation warnings for subclassing `AbstractChildWatcher` (#99386)
-rw-r--r--Doc/library/asyncio-policy.rst3
-rw-r--r--Doc/whatsnew/3.12.rst4
-rw-r--r--Lib/asyncio/unix_events.py7
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py9
-rw-r--r--Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst1
5 files changed, 21 insertions, 3 deletions
diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst
index 052378ef32..98c8501587 100644
--- a/Doc/library/asyncio-policy.rst
+++ b/Doc/library/asyncio-policy.rst
@@ -222,6 +222,9 @@ implementation used by the asyncio event loop:
This method has to be called to ensure that underlying
resources are cleaned-up.
+ .. deprecated:: 3.12
+
+
.. class:: ThreadedChildWatcher
This implementation starts a new waiting thread for every subprocess spawn.
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index 37b9fb1ea4..ead2a9e718 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -203,8 +203,8 @@ asyncio
(Contributed by Kumar Aditya in :gh:`98024`.)
* The child watcher classes :class:`~asyncio.MultiLoopChildWatcher`,
- :class:`~asyncio.FastChildWatcher` and
- :class:`~asyncio.SafeChildWatcher` are deprecated and
+ :class:`~asyncio.FastChildWatcher`, :class:`~asyncio.AbstractChildWatcher`
+ and :class:`~asyncio.SafeChildWatcher` are deprecated and
will be removed in Python 3.14. It is recommended to not manually
configure a child watcher as the event loop now uses the best available
child watcher for each platform (:class:`~asyncio.PidfdChildWatcher`
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 2de7a1bfd6..b21e039414 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -846,6 +846,13 @@ class AbstractChildWatcher:
waitpid(-1), there should be only one active object per process.
"""
+ def __init_subclass__(cls) -> None:
+ if cls.__module__ != __name__:
+ warnings._deprecated("AbstractChildWatcher",
+ "{name!r} is deprecated as of Python 3.12 and will be "
+ "removed in Python {remove}.",
+ remove=(3, 14))
+
def add_child_handler(self, pid, callback, *args):
"""Register a new child handler.
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index d806ed497a..93e8611f18 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -1108,6 +1108,11 @@ class UnixWritePipeTransportTests(test_utils.TestCase):
class AbstractChildWatcherTests(unittest.TestCase):
+ def test_warns_on_subclassing(self):
+ with self.assertWarns(DeprecationWarning):
+ class MyWatcher(asyncio.AbstractChildWatcher):
+ pass
+
def test_not_implemented(self):
f = mock.Mock()
watcher = asyncio.AbstractChildWatcher()
@@ -1747,7 +1752,9 @@ class PolicyTests(unittest.TestCase):
self.assertIsInstance(policy.get_event_loop(),
asyncio.AbstractEventLoop)
- watcher = policy.get_child_watcher()
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ watcher = policy.get_child_watcher()
self.assertIsInstance(watcher, asyncio.SafeChildWatcher)
self.assertIsNone(watcher._loop)
diff --git a/Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst b/Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst
new file mode 100644
index 0000000000..5e649a88fd
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-11-11-18-23-41.gh-issue-94597.m6vMDK.rst
@@ -0,0 +1 @@
+Deprecate :class:`asyncio.AbstractChildWatcher` to be removed in Python 3.14. Patch by Kumar Aditya.