MCPcopy Index your code
hub / github.com/python/cpython / remove_signal_handler

Method remove_signal_handler

Lib/asyncio/unix_events.py:145–175  ·  view source on GitHub ↗

Remove a handler for a signal. UNIX only. Return True if a signal handler was removed, False if not.

(self, sig)

Source from the content-addressed store, hash-verified

143 self._add_callback_signalsafe(handle)
144
145 def remove_signal_handler(self, sig):
146 """Remove a handler for a signal. UNIX only.
147
148 Return True if a signal handler was removed, False if not.
149 """
150 self._check_signal(sig)
151 try:
152 del self._signal_handlers[sig]
153 except KeyError:
154 return False
155
156 if sig == signal.SIGINT:
157 handler = signal.default_int_handler
158 else:
159 handler = signal.SIG_DFL
160
161 try:
162 signal.signal(sig, handler)
163 except OSError as exc:
164 if exc.errno == errno.EINVAL:
165 raise RuntimeError(f'sig {sig} cannot be caught')
166 else:
167 raise
168
169 if not self._signal_handlers:
170 try:
171 signal.set_wakeup_fd(-1)
172 except (ValueError, OSError) as exc:
173 logger.info('set_wakeup_fd(-1) failed: %s', exc)
174
175 return True
176
177 def _check_signal(self, sig):
178 """Internal helper to validate a signal.

Callers 2

closeMethod · 0.95
_handle_signalMethod · 0.95

Calls 3

_check_signalMethod · 0.95
set_wakeup_fdMethod · 0.80
infoMethod · 0.45

Tested by

no test coverage detected