Executable generated from python script with pyinstaller is not handling ctrl+z interrupt as expected

44 views
Skip to first unread message

Koushy

unread,
Jul 11, 2023, 2:46:19 AM7/11/23
to PyInstaller
I am working on a python script(test.py) which needs to handle ctrl+c and ctrl+z. using signal handler(signal.signal) to achieve this. when the script is executed directly ie., python3 test.py ,ctrl+c and ctrl+z are getting handled.


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?


Reply all
Reply to author
Forward
0 new messages