Skip to content

Restore OS-level signal handler after changing it in plt.pause() #29947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import time
import weakref
from weakref import WeakKeyDictionary
from ctypes import c_int, c_void_p, pythonapi

import numpy as np

Expand All @@ -59,6 +60,11 @@
from matplotlib._enums import JoinStyle, CapStyle


pythonapi.PyOS_getsig.restype = c_void_p
pythonapi.PyOS_getsig.argtypes = (c_int,)
pythonapi.PyOS_setsig.restype = c_void_p
pythonapi.PyOS_setsig.argtypes = (c_int, c_void_p)

_log = logging.getLogger(__name__)
_default_filetypes = {
'eps': 'Encapsulated Postscript',
Expand Down Expand Up @@ -1655,6 +1661,10 @@ def _allow_interrupt(prepare_notifier, handle_sigint):
old_wakeup_fd = signal.set_wakeup_fd(wsock.fileno())
notifier = prepare_notifier(rsock)

# Save OS level sigint handlers
# See https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1576
sigint_os = pythonapi.PyOS_getsig(signal.SIGINT)

def save_args_and_handle_sigint(*args):
nonlocal handler_args
handler_args = args
Expand All @@ -1668,6 +1678,7 @@ def save_args_and_handle_sigint(*args):
rsock.close()
signal.set_wakeup_fd(old_wakeup_fd)
signal.signal(signal.SIGINT, old_sigint_handler)
pythonapi.PyOS_setsig(signal.SIGINT, sigint_os)
if handler_args is not None:
old_sigint_handler(*handler_args)

Expand Down
Loading