-
-
Notifications
You must be signed in to change notification settings - Fork 178
Refuse handlers if the child watcher has no loop attached #391
Changes from all commits
f348122
f7a5259
9ab6168
d4b53cb
256e713
99148c2
08190f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,6 +433,13 @@ def kill_running(): | |
# the transport was not notified yet | ||
self.assertFalse(killed) | ||
|
||
# Unlike SafeChildWatcher, FastChildWatcher does not pop the | ||
# callbacks if waitpid() is called elsewhere. Let's clear them | ||
# manually to avoid a warning when the watcher is detached. | ||
if sys.platform != 'win32' and \ | ||
isinstance(self, SubprocessFastWatcherTests): | ||
asyncio.get_child_watcher()._callbacks.clear() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something new... Is there any reason you do this as part of this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, otherwise a warning from f7a5259 is generated. Weirdly enough it only happens with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just had a deeper look and we can get rid of this addition by fixing
This also allows us to get rid of some complexity in
All the tests run OK after those modifications. Let me know which solution you prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not so sure about this solution. Let's keep the current hack-ish code. |
||
|
||
def test_popen_error(self): | ||
# Issue #24763: check that the subprocess transport is closed | ||
# when BaseSubprocessTransport fails | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import tempfile | ||
import threading | ||
import unittest | ||
import warnings | ||
from unittest import mock | ||
|
||
if sys.platform == 'win32': | ||
|
@@ -1396,7 +1397,9 @@ def test_set_loop_race_condition(self, m): | |
with mock.patch.object( | ||
old_loop, "remove_signal_handler") as m_remove_signal_handler: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, it's much cleaner now! |
||
self.watcher.attach_loop(None) | ||
with self.assertWarnsRegex( | ||
RuntimeWarning, 'A loop is being detached'): | ||
self.watcher.attach_loop(None) | ||
|
||
m_remove_signal_handler.assert_called_once_with( | ||
signal.SIGCHLD) | ||
|
@@ -1468,6 +1471,15 @@ def test_close(self, m): | |
if isinstance(self.watcher, asyncio.FastChildWatcher): | ||
self.assertFalse(self.watcher._zombies) | ||
|
||
@waitpid_mocks | ||
def test_add_child_handler_with_no_loop_attached(self, m): | ||
callback = mock.Mock() | ||
with self.create_watcher() as watcher: | ||
with self.assertRaisesRegex( | ||
RuntimeError, | ||
'the child watcher does not have a loop attached'): | ||
watcher.add_child_handler(100, callback) | ||
|
||
|
||
class SafeChildWatcherTests (ChildWatcherTestsMixin, test_utils.TestCase): | ||
def create_watcher(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!