Module written in C does not repond to Ctrl-C interruption.

fraca7 fraca7 at
Fri Mar 3 15:00:28 CET 2006

Bo Peng a écrit :
> Dear list,
> I have not done a thorough test, but it occurs to me that
> 1. python code can be interrupted by Ctrl-C.
> 2. A C module, if I add a main() function and run independently, can be 
> interrupted by Ctrl-C.
> 3. If I load the C module in python and run, the program will not 
> respond to Ctrl-C interruption. I have to kill python explicitly.
> If this is a known behavior or just a special case of mine? Any fix to 
> it? I am using python 2.3.4 under Redhat EL4 with gcc 3.3.4.

You may want to call intrcheck() or PyErr_CheckSignals in your C code 
and react accordingly.

 From what I can see, PyErr_CheckSignals() returns 0 if no interrupt 
occurred and -1 (setting a KeyboardInterrupt exception) if one did.

More information about the Python-list mailing list