cat test.py
import signal
import time
def handler_c(signum, frame):
print("caught ^C")
def handler_z(signum, frame):
print("caught ^Z")
def test():
signal.signal(signal.SIGINT, handler_c)
signal.signal(signal.SIGTSTP, handler_z)
time.sleep(50)
test()
output:
python3 test.py
^Ccaught ^C
^Zcaught ^Z
^Ccaught ^C
when a binary is generated with pyinstaller for the above script and tried to interrupt the binary execution with ctrl+c and ctrl+z, ctrl+c got handled properly. but ctrl+z is not handled properly. Though the handler got executed, the process is getting suspended.
# pyinstaller --onefile test.py
./dist/test (test is the binary generated with pyinstaller)
^Ccaught ^C
^Zcaught ^Z
[1]+ Stopped ./dist/test
Version:
Python 3.6.8,
PyInstaller: 4.10
how to handle ctrl+z in the binary generated with pyinstaller?