[Python-Dev] Catch SIGINT at Python startup

Victor Stinner victor.stinner at haypocalc.com
Mon Mar 8 14:12:51 CET 2010


Hi,

I wrote patches for the issue #3137 and I would like your opinion about my 
solution (not directly about the patches): I propose to consider a SIGINT 
during startup as a fatal error. If you press CTRL+c while Python is starting, 
Python displays an error and exit with the code 1.

Currently, if you press CTRL+c while Python is starting: the SIGINT signal 
will be *ignored* somewhere between Python initialization and the first Python 
instruction. First problem is that if site import is interrupted, Python is 
not completly initialized (if a SIGINT is sent just after the call to 
initsigs(), initsite() is completly skipped).

Example:
------------------
$ python
^C
Traceback (most recent call last):                                                                                                     
  File "/home/SHARE/SVN/python-trunk/Lib/site.py", line 62, in <module>                                                                
    import os                                                                                                                          
  File "/home/SHARE/SVN/python-trunk/Lib/os.py", line 44, in <module>                                                                  
    from posix import *                                                                                                                
KeyboardInterrupt         
$ echo $?
1
------------------

It's not easy to reproduce this issue because Python initialization is really 
fast (yeah really! or at least to fast for me ;-)). I'm using "valgrind --log-
file=/dev/null ./python -v" to simulate a very slow computer :-)

-- 
Victor Stinner
http://www.haypocalc.com/


More information about the Python-Dev mailing list