summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2022-09-17 14:12:45 -0700
committerGitHub <noreply@github.com>2022-09-17 14:12:45 -0700
commit487135a396a504482ae3a7e9c7f80a44627a5a3f (patch)
treeecd59a74af59759d07477126b7e8a340274c6ec4
parent7e36abbb7815b14777c207dba0fe6fcd41d6d37a (diff)
downloadcpython-git-487135a396a504482ae3a7e9c7f80a44627a5a3f.tar.gz
Revert "gh-87079: Warn on unintended signal wakeup fd override in `asyncio` (#96807)" (#96898)
This reverts commit 05878106989c6f5b9dd35a6c15a21bee59312827. Reason: This broke buildbots (some warnings added by that commit are turned to errors in the SSL buildbot). Repro: ./python Lib/test/ssltests.py
-rw-r--r--Lib/asyncio/proactor_events.py14
-rw-r--r--Lib/asyncio/unix_events.py19
-rw-r--r--Lib/test/test_asyncio/test_proactor_events.py15
-rw-r--r--Lib/test/test_asyncio/test_unix_events.py24
-rw-r--r--Misc/NEWS.d/next/Library/2022-09-14-19-15-01.gh-issue-87079.0zYmW5.rst2
5 files changed, 8 insertions, 66 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 4808c5dfc4..ddb9daca02 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -635,12 +635,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
self._make_self_pipe()
if threading.current_thread() is threading.main_thread():
# wakeup fd can only be installed to a file descriptor from the main thread
- oldfd = signal.set_wakeup_fd(self._csock.fileno())
- if oldfd != -1:
- warnings.warn(
- "Signal wakeup fd was already set",
- ResourceWarning,
- source=self)
+ signal.set_wakeup_fd(self._csock.fileno())
def _make_socket_transport(self, sock, protocol, waiter=None,
extra=None, server=None):
@@ -689,12 +684,7 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
return
if threading.current_thread() is threading.main_thread():
- oldfd = signal.set_wakeup_fd(-1)
- if oldfd != self._csock.fileno():
- warnings.warn(
- "Got unexpected signal wakeup fd",
- ResourceWarning,
- source=self)
+ signal.set_wakeup_fd(-1)
# Call these methods before closing the event loop (before calling
# BaseEventLoop.close), because they can schedule callbacks with
# call_soon(), which is forbidden when the event loop is closed.
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 6c9a89dbc5..cf7683fee6 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -65,9 +65,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
self._signal_handlers = {}
def close(self):
- # remove signal handlers first to verify
- # the loop's signal handling setup has not
- # been tampered with
+ super().close()
if not sys.is_finalizing():
for sig in list(self._signal_handlers):
self.remove_signal_handler(sig)
@@ -79,7 +77,6 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
ResourceWarning,
source=self)
self._signal_handlers.clear()
- super().close()
def _process_self_data(self, data):
for signum in data:
@@ -105,12 +102,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
# main thread. By calling it early we ensure that an
# event loop running in another thread cannot add a signal
# handler.
- oldfd = signal.set_wakeup_fd(self._csock.fileno())
- if oldfd != -1 and oldfd != self._csock.fileno():
- warnings.warn(
- "Signal wakeup fd was already set",
- ResourceWarning,
- source=self)
+ signal.set_wakeup_fd(self._csock.fileno())
except (ValueError, OSError) as exc:
raise RuntimeError(str(exc))
@@ -174,12 +166,7 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
if not self._signal_handlers:
try:
- oldfd = signal.set_wakeup_fd(-1)
- if oldfd != -1 and oldfd != self._csock.fileno():
- warnings.warn(
- "Got unexpected signal wakeup fd",
- ResourceWarning,
- source=self)
+ signal.set_wakeup_fd(-1)
except (ValueError, OSError) as exc:
logger.info('set_wakeup_fd(-1) failed: %s', exc)
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index 6b28348a71..7fca0541ee 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -720,12 +720,8 @@ 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') as set_wakeup_fd:
- set_wakeup_fd.return_value = -1000
- with self.assertWarnsRegex(
- ResourceWarning, 'Signal wakeup fd was already set'
- ):
- loop = BaseProactorEventLoop(self.proactor)
+ with mock.patch('signal.set_wakeup_fd'):
+ loop = BaseProactorEventLoop(self.proactor)
self.assertIs(loop._ssock, ssock)
self.assertIs(loop._csock, csock)
self.assertEqual(loop._internal_fds, 1)
@@ -744,12 +740,7 @@ class BaseProactorEventLoopTests(test_utils.TestCase):
def test_close(self):
self.loop._close_self_pipe = mock.Mock()
- 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.loop.close()
self.assertTrue(self.loop._close_self_pipe.called)
self.assertTrue(self.proactor.close.called)
self.assertIsNone(self.loop._proactor)
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 1ec627f63e..5bad21ecba 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -89,17 +89,6 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
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
@@ -225,19 +214,6 @@ class SelectorEventLoopSignalTests(test_utils.TestCase):
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
m_signal.valid_signals = signal.valid_signals
diff --git a/Misc/NEWS.d/next/Library/2022-09-14-19-15-01.gh-issue-87079.0zYmW5.rst b/Misc/NEWS.d/next/Library/2022-09-14-19-15-01.gh-issue-87079.0zYmW5.rst
deleted file mode 100644
index 989c6dda91..0000000000
--- a/Misc/NEWS.d/next/Library/2022-09-14-19-15-01.gh-issue-87079.0zYmW5.rst
+++ /dev/null
@@ -1,2 +0,0 @@
-Warn the user whenever asyncio event loops override a signal wake up file
-descriptor that was previously set.