Skip to content
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

Signals are not handled #5113

Open
olivierlemasle opened this issue Nov 7, 2023 · 5 comments
Open

Signals are not handled #5113

olivierlemasle opened this issue Nov 7, 2023 · 5 comments
Labels
C-compat A discrepancy between RustPython and CPython

Comments

@olivierlemasle
Copy link
Contributor

olivierlemasle commented Nov 7, 2023

Feature

Signal does not seem to work with RustPython.

With the following Python file test_signal.py:

import signal
import sys

def signal_handler(signum, frame):
    print('\nSignal handler called with signal', signum)
    sys.exit(0)

signal.signal(signal.SIGQUIT, signal_handler)
signal.signal(signal.SIGINT, signal_handler)

while True:
    input(">>")

With CPython, when running python test_signal.py:

  • typing Ctrl+C or sending SIGINT (e.g. with pkill -INT -ef test_signal.py) exits the process with code 0, and Signal handler called with signal 2 is printed.
  • typing Ctrl+\ or sending SIGQUIT (e.g. with pkill -QUIT -ef test_signal.py) exits the process with code 0, and Signal handler called with signal 3 is printed.

With RustPython (compiled from main (af884cb), when running rustpython test_signal.py:

  • typing Ctrl+C or Ctrl+\ exists the process with error code 130, and a KeyboardInterrupt message is printed:
     Traceback (most recent call last):
       File "test_signal.py", line 12, in <module>
         input(">>")
     KeyboardInterrupt
    
  • sending SIGINT or SIGQUIT has no effect

Python Documentation or reference to CPython source code

https://docs.python.org/3/library/signal.html

@olivierlemasle olivierlemasle added the C-compat A discrepancy between RustPython and CPython label Nov 7, 2023
@youknowone
Copy link
Member

@coolreader18 do you have any idea about this?

@coolreader18
Copy link
Member

Probably vm/src/stdlib/builtins.rs:418 should call the signal handler instead of unconditionally throwing a KeyboardInterrupt

@andreistan26
Copy link

The problem is that rustyline disables these signals from termios. I've opened an issue on their side to add a config option for this kkawakam/rustyline#757.

https://github.com/kkawakam/rustyline/blob/c01855af1cbfe1f3ded3f7bfbde5efab17a78240/src/tty/unix.rs#L1568

        // disable echoing, canonical mode, extended input processing and signals
        raw.c_lflag &= !(termios::ECHO | termios::ICANON | termios::IEXTEN | termios::ISIG);

@youknowone
Copy link
Member

The linked issue in rustyline looks resolved. Is this issue also solved?

@andreistan26
Copy link

Yep, submitted the PR a while ago. The issue is not solved though. The setup for rustyline needs to change a bit. If i get some time i will take a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-compat A discrepancy between RustPython and CPython
Projects
None yet
Development

No branches or pull requests

4 participants