Skip to content

Commit aa87432

Browse files
authoredNov 12, 2022
GH-94597: add deprecation warnings for subclassing AbstractChildWatcher (#99386)
1 parent e02cc6d commit aa87432

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed
 

‎Doc/library/asyncio-policy.rst

+3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ implementation used by the asyncio event loop:
222222
This method has to be called to ensure that underlying
223223
resources are cleaned-up.
224224

225+
.. deprecated:: 3.12
226+
227+
225228
.. class:: ThreadedChildWatcher
226229

227230
This implementation starts a new waiting thread for every subprocess spawn.

‎Doc/whatsnew/3.12.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ asyncio
203203
(Contributed by Kumar Aditya in :gh:`98024`.)
204204

205205
* The child watcher classes :class:`~asyncio.MultiLoopChildWatcher`,
206-
:class:`~asyncio.FastChildWatcher` and
207-
:class:`~asyncio.SafeChildWatcher` are deprecated and
206+
:class:`~asyncio.FastChildWatcher`, :class:`~asyncio.AbstractChildWatcher`
207+
and :class:`~asyncio.SafeChildWatcher` are deprecated and
208208
will be removed in Python 3.14. It is recommended to not manually
209209
configure a child watcher as the event loop now uses the best available
210210
child watcher for each platform (:class:`~asyncio.PidfdChildWatcher`

‎Lib/asyncio/unix_events.py

+7
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,13 @@ class AbstractChildWatcher:
846846
waitpid(-1), there should be only one active object per process.
847847
"""
848848

849+
def __init_subclass__(cls) -> None:
850+
if cls.__module__ != __name__:
851+
warnings._deprecated("AbstractChildWatcher",
852+
"{name!r} is deprecated as of Python 3.12 and will be "
853+
"removed in Python {remove}.",
854+
remove=(3, 14))
855+
849856
def add_child_handler(self, pid, callback, *args):
850857
"""Register a new child handler.
851858

‎Lib/test/test_asyncio/test_unix_events.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,11 @@ def test_write_eof_pending(self):
11081108

11091109
class AbstractChildWatcherTests(unittest.TestCase):
11101110

1111+
def test_warns_on_subclassing(self):
1112+
with self.assertWarns(DeprecationWarning):
1113+
class MyWatcher(asyncio.AbstractChildWatcher):
1114+
pass
1115+
11111116
def test_not_implemented(self):
11121117
f = mock.Mock()
11131118
watcher = asyncio.AbstractChildWatcher()
@@ -1747,7 +1752,9 @@ def f():
17471752

17481753
self.assertIsInstance(policy.get_event_loop(),
17491754
asyncio.AbstractEventLoop)
1750-
watcher = policy.get_child_watcher()
1755+
with warnings.catch_warnings():
1756+
warnings.simplefilter("ignore", DeprecationWarning)
1757+
watcher = policy.get_child_watcher()
17511758

17521759
self.assertIsInstance(watcher, asyncio.SafeChildWatcher)
17531760
self.assertIsNone(watcher._loop)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate :class:`asyncio.AbstractChildWatcher` to be removed in Python 3.14. Patch by Kumar Aditya.

0 commit comments

Comments
 (0)
Please sign in to comment.