mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +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
|
@ -88,6 +88,17 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
|
|||
self.loop.add_signal_handler,
|
||||
signal.SIGINT, lambda: True)
|
||||
|
||||
@mock.patch('asyncio.unix_events.signal')
|
||||
def test_add_signal_handler_setup_warn(self, m_signal):
|
||||
m_signal.NSIG = signal.NSIG
|
||||
m_signal.valid_signals = signal.valid_signals
|
||||
m_signal.set_wakeup_fd.return_value = -1000
|
||||
|
||||
with self.assertWarnsRegex(
|
||||
ResourceWarning, 'Signal wakeup fd was already set'
|
||||
):
|
||||
self.loop.add_signal_handler(signal.SIGINT, lambda: True)
|
||||
|
||||
@mock.patch('asyncio.unix_events.signal')
|
||||
def test_add_signal_handler_coroutine_error(self, m_signal):
|
||||
m_signal.NSIG = signal.NSIG
|
||||
|
@ -213,6 +224,19 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
|
|||
self.loop.remove_signal_handler(signal.SIGHUP)
|
||||
self.assertTrue(m_logging.info)
|
||||
|
||||
@mock.patch('asyncio.unix_events.signal')
|
||||
def test_remove_signal_handler_cleanup_warn(self, m_signal):
|
||||
m_signal.NSIG = signal.NSIG
|
||||
m_signal.valid_signals = signal.valid_signals
|
||||
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
|
||||
|
||||
m_signal.set_wakeup_fd.return_value = -1000
|
||||
|
||||
with self.assertWarnsRegex(
|
||||
ResourceWarning, 'Got unexpected signal wakeup fd'
|
||||
):
|
||||
self.loop.remove_signal_handler(signal.SIGHUP)
|
||||
|
||||
@mock.patch('asyncio.unix_events.signal')
|
||||
def test_remove_signal_handler_error(self, m_signal):
|
||||
m_signal.NSIG = signal.NSIG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue