diff options
| author | Michel Hidalgo <michel@ekumenlabs.com> | 2022-09-17 15:07:54 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-17 15:07:54 (GMT) |
| commit | 05878106989c6f5b9dd35a6c15a21bee59312827 (patch) | |
| tree | 8d58f02a0cc3e14d4983106033a5d97e4cd49bf1 /Lib/asyncio/proactor_events.py | |
| parent | 2cd70ffb3fe22d778d0bb6ec220fdf67dccc1be6 (diff) | |
| download | cpython-05878106989c6f5b9dd35a6c15a21bee59312827.zip cpython-05878106989c6f5b9dd35a6c15a21bee59312827.tar.gz cpython-05878106989c6f5b9dd35a6c15a21bee59312827.tar.bz2 | |
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.
Diffstat (limited to 'Lib/asyncio/proactor_events.py')
| -rw-r--r-- | Lib/asyncio/proactor_events.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py index ddb9dac..4808c5d 100644 --- a/Lib/asyncio/proactor_events.py +++ b/Lib/asyncio/proactor_events.py @@ -635,7 +635,12 @@ 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 - signal.set_wakeup_fd(self._csock.fileno()) + oldfd = signal.set_wakeup_fd(self._csock.fileno()) + if oldfd != -1: + warnings.warn( + "Signal wakeup fd was already set", + ResourceWarning, + source=self) def _make_socket_transport(self, sock, protocol, waiter=None, extra=None, server=None): @@ -684,7 +689,12 @@ class BaseProactorEventLoop(base_events.BaseEventLoop): return if threading.current_thread() is threading.main_thread(): - signal.set_wakeup_fd(-1) + oldfd = signal.set_wakeup_fd(-1) + if oldfd != self._csock.fileno(): + warnings.warn( + "Got unexpected signal wakeup fd", + ResourceWarning, + source=self) # 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. |
