mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-87079: Warn on unintended signal wakeup fd override in asyncio
(#96807)
Warn on loop initialization, when setting the wakeup fd disturbs a previously set wakeup fd, and on loop closing, when upon resetting the wakeup fd, we find it has been changed by someone else.
This commit is contained in:
parent
2cd70ffb3f
commit
0587810698
5 changed files with 66 additions and 8 deletions
|
@ -720,8 +720,12 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
|
|||
def test_ctor(self, socketpair):
|
||||
ssock, csock = socketpair.return_value = (
|
||||
mock.Mock(), mock.Mock())
|
||||
with mock.patch('signal.set_wakeup_fd'):
|
||||
loop = BaseProactorEventLoop(self.proactor)
|
||||
with mock.patch('signal.set_wakeup_fd') as set_wakeup_fd:
|
||||
set_wakeup_fd.return_value = -1000
|
||||
with self.assertWarnsRegex(
|
||||
ResourceWarning, 'Signal wakeup fd was already set'
|
||||
):
|
||||
loop = BaseProactorEventLoop(self.proactor)
|
||||
self.assertIs(loop._ssock, ssock)
|
||||
self.assertIs(loop._csock, csock)
|
||||
self.assertEqual(loop._internal_fds, 1)
|
||||
|
@ -740,7 +744,12 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
|
|||
|
||||
def test_close(self):
|
||||
self.loop._close_self_pipe = mock.Mock()
|
||||
self.loop.close()
|
||||
with mock.patch('signal.set_wakeup_fd') as set_wakeup_fd:
|
||||
set_wakeup_fd.return_value = -1000
|
||||
with self.assertWarnsRegex(
|
||||
ResourceWarning, 'Got unexpected signal wakeup fd'
|
||||
):
|
||||
self.loop.close()
|
||||
self.assertTrue(self.loop._close_self_pipe.called)
|
||||
self.assertTrue(self.proactor.close.called)
|
||||
self.assertIsNone(self.loop._proactor)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue