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

Diez B. Roggisch deets at nospam.web.de
Fri Feb 24 11:33:58 EST 2006


Bo Peng wrote:

> 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.

I fear it is a known behavior and not easy to fix. See the module signal
docs:

"""
Although Python signal handlers are called asynchronously as far as the
Python user is concerned, they can only occur between the ``atomic''
instructions of the Python interpreter. This means that signals arriving
during long calculations implemented purely in C (such as regular
expression matches on large bodies of text) may be delayed for an arbitrary
amount of time. 
"""

So - no workaround here, unless you patch python.

Diez



More information about the Python-list mailing list