Skip to content

Commit 8cf0fc2

Browse files
authored
Revert "gh-87079: Warn on unintended signal wakeup fd override in asyncio (#96807)"
This reverts commit 0587810.
1 parent 7e36abb commit 8cf0fc2

File tree

5 files changed

+8
-66
lines changed

5 files changed

+8
-66
lines changed

Lib/asyncio/proactor_events.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,7 @@ def __init__(self, proactor):
635635
self._make_self_pipe()
636636
if threading.current_thread() is threading.main_thread():
637637
# wakeup fd can only be installed to a file descriptor from the main thread
638-
oldfd = signal.set_wakeup_fd(self._csock.fileno())
639-
if oldfd != -1:
640-
warnings.warn(
641-
"Signal wakeup fd was already set",
642-
ResourceWarning,
643-
source=self)
638+
signal.set_wakeup_fd(self._csock.fileno())
644639

645640
def _make_socket_transport(self, sock, protocol, waiter=None,
646641
extra=None, server=None):
@@ -689,12 +684,7 @@ def close(self):
689684
return
690685

691686
if threading.current_thread() is threading.main_thread():
692-
oldfd = signal.set_wakeup_fd(-1)
693-
if oldfd != self._csock.fileno():
694-
warnings.warn(
695-
"Got unexpected signal wakeup fd",
696-
ResourceWarning,
697-
source=self)
687+
signal.set_wakeup_fd(-1)
698688
# Call these methods before closing the event loop (before calling
699689
# BaseEventLoop.close), because they can schedule callbacks with
700690
# call_soon(), which is forbidden when the event loop is closed.

Lib/asyncio/unix_events.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def __init__(self, selector=None):
6565
self._signal_handlers = {}
6666

6767
def close(self):
68-
# remove signal handlers first to verify
69-
# the loop's signal handling setup has not
70-
# been tampered with
68+
super().close()
7169
if not sys.is_finalizing():
7270
for sig in list(self._signal_handlers):
7371
self.remove_signal_handler(sig)
@@ -79,7 +77,6 @@ def close(self):
7977
ResourceWarning,
8078
source=self)
8179
self._signal_handlers.clear()
82-
super().close()
8380

8481
def _process_self_data(self, data):
8582
for signum in data:
@@ -105,12 +102,7 @@ def add_signal_handler(self, sig, callback, *args):
105102
# main thread. By calling it early we ensure that an
106103
# event loop running in another thread cannot add a signal
107104
# handler.
108-
oldfd = signal.set_wakeup_fd(self._csock.fileno())
109-
if oldfd != -1 and oldfd != self._csock.fileno():
110-
warnings.warn(
111-
"Signal wakeup fd was already set",
112-
ResourceWarning,
113-
source=self)
105+
signal.set_wakeup_fd(self._csock.fileno())
114106
except (ValueError, OSError) as exc:
115107
raise RuntimeError(str(exc))
116108

@@ -174,12 +166,7 @@ def remove_signal_handler(self, sig):
174166

175167
if not self._signal_handlers:
176168
try:
177-
oldfd = signal.set_wakeup_fd(-1)
178-
if oldfd != -1 and oldfd != self._csock.fileno():
179-
warnings.warn(
180-
"Got unexpected signal wakeup fd",
181-
ResourceWarning,
182-
source=self)
169+
signal.set_wakeup_fd(-1)
183170
except (ValueError, OSError) as exc:
184171
logger.info('set_wakeup_fd(-1) failed: %s', exc)
185172

Lib/test/test_asyncio/test_proactor_events.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -720,12 +720,8 @@ def setUp(self):
720720
def test_ctor(self, socketpair):
721721
ssock, csock = socketpair.return_value = (
722722
mock.Mock(), mock.Mock())
723-
with mock.patch('signal.set_wakeup_fd') as set_wakeup_fd:
724-
set_wakeup_fd.return_value = -1000
725-
with self.assertWarnsRegex(
726-
ResourceWarning, 'Signal wakeup fd was already set'
727-
):
728-
loop = BaseProactorEventLoop(self.proactor)
723+
with mock.patch('signal.set_wakeup_fd'):
724+
loop = BaseProactorEventLoop(self.proactor)
729725
self.assertIs(loop._ssock, ssock)
730726
self.assertIs(loop._csock, csock)
731727
self.assertEqual(loop._internal_fds, 1)
@@ -744,12 +740,7 @@ def test_close_self_pipe(self):
744740

745741
def test_close(self):
746742
self.loop._close_self_pipe = mock.Mock()
747-
with mock.patch('signal.set_wakeup_fd') as set_wakeup_fd:
748-
set_wakeup_fd.return_value = -1000
749-
with self.assertWarnsRegex(
750-
ResourceWarning, 'Got unexpected signal wakeup fd'
751-
):
752-
self.loop.close()
743+
self.loop.close()
753744
self.assertTrue(self.loop._close_self_pipe.called)
754745
self.assertTrue(self.proactor.close.called)
755746
self.assertIsNone(self.loop._proactor)

Lib/test/test_asyncio/test_unix_events.py

-24
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ def test_add_signal_handler_setup_error(self, m_signal):
8888
self.loop.add_signal_handler,
8989
signal.SIGINT, lambda: True)
9090

91-
@mock.patch('asyncio.unix_events.signal')
92-
def test_add_signal_handler_setup_warn(self, m_signal):
93-
m_signal.NSIG = signal.NSIG
94-
m_signal.valid_signals = signal.valid_signals
95-
m_signal.set_wakeup_fd.return_value = -1000
96-
97-
with self.assertWarnsRegex(
98-
ResourceWarning, 'Signal wakeup fd was already set'
99-
):
100-
self.loop.add_signal_handler(signal.SIGINT, lambda: True)
101-
10291
@mock.patch('asyncio.unix_events.signal')
10392
def test_add_signal_handler_coroutine_error(self, m_signal):
10493
m_signal.NSIG = signal.NSIG
@@ -224,19 +213,6 @@ def test_remove_signal_handler_cleanup_error(self, m_logging, m_signal):
224213
self.loop.remove_signal_handler(signal.SIGHUP)
225214
self.assertTrue(m_logging.info)
226215

227-
@mock.patch('asyncio.unix_events.signal')
228-
def test_remove_signal_handler_cleanup_warn(self, m_signal):
229-
m_signal.NSIG = signal.NSIG
230-
m_signal.valid_signals = signal.valid_signals
231-
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
232-
233-
m_signal.set_wakeup_fd.return_value = -1000
234-
235-
with self.assertWarnsRegex(
236-
ResourceWarning, 'Got unexpected signal wakeup fd'
237-
):
238-
self.loop.remove_signal_handler(signal.SIGHUP)
239-
240216
@mock.patch('asyncio.unix_events.signal')
241217
def test_remove_signal_handler_error(self, m_signal):
242218
m_signal.NSIG = signal.NSIG

Misc/NEWS.d/next/Library/2022-09-14-19-15-01.gh-issue-87079.0zYmW5.rst

-2
This file was deleted.

0 commit comments

Comments
 (0)