mirror of
https://github.com/python/cpython.git
synced 2025-10-01 04:42:10 +00:00
[3.6] bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (GH-1319) (#1454)
* bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver
* Tweak comment.
(cherry picked from commit 6dd4d734ed
)
This commit is contained in:
parent
31906b42fd
commit
a7e48b544b
2 changed files with 17 additions and 6 deletions
|
@ -149,8 +149,15 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None):
|
||||||
|
|
||||||
util._close_stdin()
|
util._close_stdin()
|
||||||
|
|
||||||
# ignoring SIGCHLD means no need to reap zombie processes
|
# ignoring SIGCHLD means no need to reap zombie processes;
|
||||||
handler = signal.signal(signal.SIGCHLD, signal.SIG_IGN)
|
# letting SIGINT through avoids KeyboardInterrupt tracebacks
|
||||||
|
handlers = {
|
||||||
|
signal.SIGCHLD: signal.SIG_IGN,
|
||||||
|
signal.SIGINT: signal.SIG_DFL,
|
||||||
|
}
|
||||||
|
old_handlers = {sig: signal.signal(sig, val)
|
||||||
|
for (sig, val) in handlers.items()}
|
||||||
|
|
||||||
with socket.socket(socket.AF_UNIX, fileno=listener_fd) as listener, \
|
with socket.socket(socket.AF_UNIX, fileno=listener_fd) as listener, \
|
||||||
selectors.DefaultSelector() as selector:
|
selectors.DefaultSelector() as selector:
|
||||||
_forkserver._forkserver_address = listener.getsockname()
|
_forkserver._forkserver_address = listener.getsockname()
|
||||||
|
@ -175,7 +182,7 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None):
|
||||||
code = 1
|
code = 1
|
||||||
if os.fork() == 0:
|
if os.fork() == 0:
|
||||||
try:
|
try:
|
||||||
_serve_one(s, listener, alive_r, handler)
|
_serve_one(s, listener, alive_r, old_handlers)
|
||||||
except Exception:
|
except Exception:
|
||||||
sys.excepthook(*sys.exc_info())
|
sys.excepthook(*sys.exc_info())
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
@ -186,11 +193,12 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None):
|
||||||
if e.errno != errno.ECONNABORTED:
|
if e.errno != errno.ECONNABORTED:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _serve_one(s, listener, alive_r, handler):
|
def _serve_one(s, listener, alive_r, handlers):
|
||||||
# close unnecessary stuff and reset SIGCHLD handler
|
# close unnecessary stuff and reset signal handlers
|
||||||
listener.close()
|
listener.close()
|
||||||
os.close(alive_r)
|
os.close(alive_r)
|
||||||
signal.signal(signal.SIGCHLD, handler)
|
for sig, val in handlers.items():
|
||||||
|
signal.signal(sig, val)
|
||||||
|
|
||||||
# receive fds from parent process
|
# receive fds from parent process
|
||||||
fds = reduction.recvfds(s, MAXFDS_TO_SEND + 1)
|
fds = reduction.recvfds(s, MAXFDS_TO_SEND + 1)
|
||||||
|
|
|
@ -36,6 +36,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- bpo-30185: Avoid KeyboardInterrupt tracebacks in forkserver helper process
|
||||||
|
when Ctrl-C is received.
|
||||||
|
|
||||||
- bpo-28556: Various updates to typing module: add typing.NoReturn type, use
|
- bpo-28556: Various updates to typing module: add typing.NoReturn type, use
|
||||||
WrapperDescriptorType, minor bug-fixes. Original PRs by
|
WrapperDescriptorType, minor bug-fixes. Original PRs by
|
||||||
Jim Fasarakis-Hilliard and Ivan Levkivskyi.
|
Jim Fasarakis-Hilliard and Ivan Levkivskyi.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue