Skip to content

Commit 85079ad

Browse files
quark-zjujonathanslenders
authored andcommitted
Fix compatibility when SIGINT handler is installed by non-Python
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.
1 parent 2c84307 commit 85079ad

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: src/prompt_toolkit/application/application.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1621,5 +1621,6 @@ def _restore_sigint_from_ctypes() -> Generator[None, None, None]:
16211621
try:
16221622
yield
16231623
finally:
1624-
signal.signal(signal.SIGINT, sigint)
1624+
if sigint is not None:
1625+
signal.signal(signal.SIGINT, sigint)
16251626
pythonapi.PyOS_setsig(signal.SIGINT, sigint_os)

0 commit comments

Comments
 (0)