diff --git a/Doc/library/asyncio-policy.rst b/Doc/library/asyncio-policy.rst index 052378ef32743b..98c85015874689 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 37b9fb1ea4e89e..ead2a9e718a9e2 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 2de7a1bfd68155..b21e0394141bf4 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 d806ed497aaab4..93e8611f184d25 100644 --- a/Lib/test/test_asyncio/test_unix_events.py +++ b/Lib/test/test_asyncio/test_unix_events.py @@ -1108,6 +1108,11 @@ def test_write_eof_pending(self): 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 @@ def f(): 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 00000000000000..5e649a88fddeb6 --- /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.