Skip to content

Commit

Permalink
Fix compatibility when SIGINT handler is installed by non-Python
Browse files Browse the repository at this point in the history
When a native (Rust, C) program installs SIGINT handler and calls into Python,
`signal.getsignal` can return `None`, which is not a valid value for the 2nd
parameter of `signal.signal`. Fix it by checking `None` explicitly.
  • Loading branch information
quark-zju authored and jonathanslenders committed May 15, 2024
1 parent 2c84307 commit 85079ad
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/prompt_toolkit/application/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,5 +1621,6 @@ def _restore_sigint_from_ctypes() -> Generator[None, None, None]:
try:
yield
finally:
signal.signal(signal.SIGINT, sigint)
if sigint is not None:
signal.signal(signal.SIGINT, sigint)
pythonapi.PyOS_setsig(signal.SIGINT, sigint_os)

0 comments on commit 85079ad

Please sign in to comment.