I have a script server that should be able to disable. When testing regular try..except I realized that Ctrl-C does not work in the usual way. I usually complete long tasks like
try: ... except KeyboardInterrupt:
therefore, the task can be disabled on Ctrl-C . I have never encountered any problems with this before, but for some reason, when I pressed Ctrl-C , when this particular script works, the script just exits without catching Ctrl-C .
The initial version was implemented using Process from multiprocessing . I rewrote the script using Thread from threading , but in the same place. I used threading many times before, but I'm new to the multiprocessing library. In any case, I have never experienced this Ctrl-C behavior before.
Usually, I always performed the functions of sentries, etc., to close the Queues and Thread instances in an orderly manner, but this script just comes out without an answer.
Finally, I tried overriding signal.SIGINT just like this
def handler(signal, frame): print 'Ctrl+C' signal.signal(signal.SIGINT, handler) ...
Here Ctrl+C was actually caught, but the handler does not execute, it never prints anything.
Besides the threading / multiprocessing aspect, parts of the script contain C++ SWIG objects. I do not know if this is related to this. I am running Python 2.7.2 on OS X Lion.
So a few questions:
- What's going on here?
- How can I debug this?
- What do I need to know to understand the root cause?
PLEASE NOTE: The internal elements of a script are property, so I cannot provide code examples. However, I really want to get pointers to debug this myself. I am experienced enough to understand this if someone can point me in the right direction.
EDIT: I started commenting on imports, etc., to find out what caused the strange behavior, and I narrowed it down to importing the C++ SWIG . Any ideas why importing a C++ SWIG intercepts Ctrl-C ? However, I am not the author of the guilty library, and my SWIG experience is limited, so I don’t know where to start ...
EDIT 2: I just tried the same script on a Windows machine, and in Windows 7 Ctrl-C caught as expected. I am not going to worry about the OS X part, the script will work on Windows anyway.