0

Currently whenever I press CTRL + Z on a lengthy script I was given, it immediately terminates the script ([1+] stopped(SIGTSTP) ./test.py) which is what I want, but it also leaves the python2 process running (when I type ps to look at processes), which forces me to use killall -9 python2, which I do not want to do every time. Is there a way to immediately terminate a script that doesn't leave the python2 process running in the background?

There is no SIGTSTP currently in the code that I see but I did try using the following code with no luck. It didn't even exit the script when I pressed CTRL + Z.

def handler(signum, frame):
    sys.exit("CTRL+Z pressed. Exiting Test")

signal.signal(signal.SIGTSTP, handler)

2 Answers 2

1

SIGSTP is a signal to suspend a process, it sounds like you want to terminate a process. You can try sending Ctrl-C or CTRL-D instead, which should send a SIGINT signal.

I believe you could also try CTRL-\ which sends SIGQUIT.

Sign up to request clarification or add additional context in comments.

1 Comment

CTRL + D did nothing during the script. CTRL + C displayed ^C on my screen but the script continued running. CTRL + \ seems to have done the trick though. Thank you.
0

Use Ctrl + C. SIGTSTP suspends the process, hence why it keeps it open, but does not terminate it. (Note: On a Linux terminal use Ctrl + \, otherwise use Ctrl + C or Ctrl + D)

Or just use sys.exit()

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.