8000 deprecate watchers · python/cpython@fce0416 · GitHub
[go: up one dir, main page]

Skip to content

Commit fce0416

Browse files
deprecate watchers
1 parent 531ffaa commit fce0416

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ New Modules
102102
Improved Modules
103103
================
104104

105+
asyncio
106+
-------
107+
108+
* On Linux, :mod:`asyncio` uses :class:`~asyncio.PidfdChildWatcher` by default
109+
if :func:`os.pidfd_open` is available instead of
110+
:class:`~asyncio.ThreadedChildWatcher`.
111+
(Contributed by Kumar Aditya in :gh:`98024`.)
112+
113+
* :class:`~asyncio.MultiLoopChildWatcher`, :class:`~asyncio.FastChildWatcher`
114+
and :class:`~asyncio.SafeChildWatcher` child watchers are deprecated and
115+
will be removed in Python 3.14. It is recommended to not manually
116+
configure child watcher as the event loop now uses the best available
117+
child watcher for the platform.
118+
(Contributed by Kumar Aditya in :gh:`94597`.)
119+
120+
105121
pathlib
106122
-------
107123

Lib/asyncio/unix_events.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,13 @@ class SafeChildWatcher(BaseChildWatcher):
10221022
big number of children (O(n) each time SIGCHLD is raised)
10231023
"""
10241024

1025+
def __init__(self):
1026+
super().__init__()
1027+
warnings._deprecated("SafeChildWatcher",
1028+
"{name!r} is deprecated since Python 3.12 and will be "
1029+
"removed in Python {remove}.",
1030+
remove=(3, 14))
1031+
10251032
def close(self):
10261033
self._callbacks.clear()
10271034
super().close()
@@ -1100,6 +1107,10 @@ def __init__(self):
11001107
self._lock = threading.Lock()
11011108
self._zombies = {}
11021109
self._forks = 0
1110+
warnings._deprecated("FastChildWatcher",
1111+
"{name!r} is deprecated since Python 3.12 and will be "
1112+
"removed in Python {remove}.",
1113+
remove=(3, 14))
11031114

11041115
def close(self):
11051116
self._callbacks.clear()
@@ -1212,6 +1223,10 @@ class MultiLoopChildWatcher(AbstractChildWatcher):
12121223
def __init__(self):
12131224
self._callbacks = {}
12141225
self._saved_sighandler = None
1226+
warnings._deprecated("MultiLoopChildWatcher",
1227+
"{name!r} is deprecated since Python 3.12 and will be "
1228+
"removed in Python {remove}.",
1229+
remove=(3, 14))
12151230

12161231
def is_active(self):
12171232
return self._saved_sighandler is not None

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ def setUp(self):
688688
self.loop = policy.new_event_loop()
689689
self.set_event_loop(self.loop)
690690

691-
watcher = self.Watcher()
691+
watcher = self._get_watcher()
692692
watcher.attach_loop(self.loop)
693693
policy.set_child_watcher(watcher)
694694

@@ -703,32 +703,38 @@ def tearDown(self):
703703
class SubprocessThreadedWatcherTests(SubprocessWatcherMixin,
704704
test_utils.TestCase):
705705

706-
Watcher = unix_events.ThreadedChildWatcher
707-
708-
@unittest.skip("bpo-38323: MultiLoopChildWatcher has a race condition \
709-
and these tests can hang the test suite")
710-
class SubprocessMultiLoopWatcherTests(SubprocessWatcherMixin,
711-
test_utils.TestCase):
712-
713-
Watcher = unix_events.MultiLoopChildWatcher
706+
def _get_watcher(self):
707+
return unix_events.ThreadedChildWatcher()
714708

715709
class SubprocessSafeWatcherTests(SubprocessWatcherMixin,
716710
test_utils.TestCase):
717711

718-
Watcher = unix_events.SafeChildWatcher
712+
def _get_watcher(self):
713+
with self.assertWarns(DeprecationWarning):
714+
return unix_events.SafeChildWatcher()
715+
716+
class MultiLoopChildWatcherTests(test_utils.TestCase):
717+
718+
def test_warns(self):
719+
with self.assertWarns(DeprecationWarning):
720+
unix_events.MultiLoopChildWatcher()
719721

720722
class SubprocessFastWatcherTests(SubprocessWatcherMixin,
721723
test_utils.TestCase):
722724

723-
Watcher = unix_events.FastChildWatcher
725+
def _get_watcher(self):
726+
with self.assertWarns(DeprecationWarning):
727+
return unix_events.FastChildWatcher()
724728

725729
@unittest.skipUnless(
726730
_has_pidfd_support(),
727731
"operating system does not support pidfds",
728732
)
729733
class SubprocessPidfdWatcherTests(SubprocessWatcherMixin,
730734
test_utils.TestCase):
731-
Watcher = unix_events.PidfdChildWatcher
735+
736+
def _get_watcher(self):
737+
return unix_events.PidfdChildWatcher()
732738

733739

734740
class GenericWatcherTests(test_utils.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:class:`~asyncio.MultiLoopChildWatcher`, :class:`~asyncio.FastChildWatcher` and :class:`~asyncio.SafeChildWatcher` child watchers are deprecated and will be removed in Python 3.14. Patch by Kumar Aditya.

0 commit comments

Comments
 (0)
0