Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
deprecate watchers
  • Loading branch information
kumaraditya303 authored Oct 8, 2022
commit fce0416c1d10249d975f605809d074a6401b367a
16 changes: 16 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ New Modules
Improved Modules
================

asyncio
-------

* On Linux, :mod:`asyncio` uses :class:`~asyncio.PidfdChildWatcher` by default
if :func:`os.pidfd_open` is available instead of
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
:class:`~asyncio.ThreadedChildWatcher`.
(Contributed by Kumar Aditya in :gh:`98024`.)

* :class:`~asyncio.MultiLoopChildWatcher`, :class:`~asyncio.FastChildWatcher`
and :class:`~asyncio.SafeChildWatcher` child watchers are deprecated and
will be removed in Python 3.14. It is recommended to not manually
configure child watcher as the event loop now uses the best available
child watcher for the platform.
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
(Contributed by Kumar Aditya in :gh:`94597`.)


pathlib
-------

Expand Down
15 changes: 15 additions & 0 deletions Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,13 @@ class SafeChildWatcher(BaseChildWatcher):
big number of children (O(n) each time SIGCHLD is raised)
"""

def __init__(self):
super().__init__()
warnings._deprecated("SafeChildWatcher",
"{name!r} is deprecated since Python 3.12 and will be "
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
"removed in Python {remove}.",
remove=(3, 14))

def close(self):
self._callbacks.clear()
super().close()
Expand Down Expand Up @@ -1100,6 +1107,10 @@ def __init__(self):
self._lock = threading.Lock()
self._zombies = {}
self._forks = 0
warnings._deprecated("FastChildWatcher",
"{name!r} is deprecated since Python 3.12 and will be "
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
"removed in Python {remove}.",
remove=(3, 14))

def close(self):
self._callbacks.clear()
Expand Down Expand Up @@ -1212,6 +1223,10 @@ class MultiLoopChildWatcher(AbstractChildWatcher):
def __init__(self):
self._callbacks = {}
self._saved_sighandler = None
warnings._deprecated("MultiLoopChildWatcher",
"{name!r} is deprecated since Python 3.12 and will be "
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
"removed in Python {remove}.",
remove=(3, 14))

def is_active(self):
return self._saved_sighandler is not None
Expand Down
30 changes: 18 additions & 12 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def setUp(self):
self.loop = policy.new_event_loop()
self.set_event_loop(self.loop)

watcher = self.Watcher()
watcher = self._get_watcher()
watcher.attach_loop(self.loop)
policy.set_child_watcher(watcher)

Expand All @@ -703,32 +703,38 @@ def tearDown(self):
class SubprocessThreadedWatcherTests(SubprocessWatcherMixin,
test_utils.TestCase):

Watcher = unix_events.ThreadedChildWatcher

@unittest.skip("bpo-38323: MultiLoopChildWatcher has a race condition \
and these tests can hang the test suite")
class SubprocessMultiLoopWatcherTests(SubprocessWatcherMixin,
test_utils.TestCase):

Watcher = unix_events.MultiLoopChildWatcher
def _get_watcher(self):
return unix_events.ThreadedChildWatcher()

class SubprocessSafeWatcherTests(SubprocessWatcherMixin,
test_utils.TestCase):

Watcher = unix_events.SafeChildWatcher
def _get_watcher(self):
with self.assertWarns(DeprecationWarning):
return unix_events.SafeChildWatcher()

class MultiLoopChildWatcherTests(test_utils.TestCase):

def test_warns(self):
with self.assertWarns(DeprecationWarning):
unix_events.MultiLoopChildWatcher()

class SubprocessFastWatcherTests(SubprocessWatcherMixin,
test_utils.TestCase):

Watcher = unix_events.FastChildWatcher
def _get_watcher(self):
with self.assertWarns(DeprecationWarning):
return unix_events.FastChildWatcher()

@unittest.skipUnless(
_has_pidfd_support(),
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated
"operating system does not support pidfds",
)
class SubprocessPidfdWatcherTests(SubprocessWatcherMixin,
test_utils.TestCase):
Watcher = unix_events.PidfdChildWatcher

def _get_watcher(self):
return unix_events.PidfdChildWatcher()


class GenericWatcherTests(test_utils.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated