Annoying message when interrupting python scripts

G

geoffbache

Hi all,

I find that I semi-frequently get the cryptic message

import site failed; use -v for traceback

printed on standard error when an arbitrary python script receives
SIGINT while the python interpreter
is still firing up. If I use -v for traceback I get something along
the lines of

'import site' failed; traceback:
Traceback (most recent call last):
File "/usr/lib/python2.4/site.py", line 61, in ?
import os
File "/usr/lib/python2.4/os.py", line 683, in ?
import copy_reg as _copy_reg
File "/usr/lib/python2.4/copy_reg.py", line 5, in ?
"""
KeyboardInterrupt

Is this a bug? I couldn't find any code, but I imagine something like
try:
import site
except:
sys.stderr.write("import site failed; use -v for traceback\n")

which should surely allow a KeyboardInterrupt exception through?

Regards,
Geoff Bache
 
G

geoffbache

To clarify: this is more serious than an incorrect error message, as
the intended interrupt gets swallowed and
script execution proceeds. Sometimes I seem to get half-imported
modules as well,
the script failing later with something like

AttributeError: 'module' object has no attribute 'getenv'

when trying to call os.getenv

Regards,
Geoff Bache
 
J

John Machin

Is this a bug? I couldn't find any code, but I imagine something like
try:
import site
except:
sys.stderr.write("import site failed; use -v for traceback\n")

which should surely allow a KeyboardInterrupt exception through?

Surely?? A bare "except" catches *all* remaining uncaught exceptions.
Allowing a KeyboardInterrupt exception through would require:
except KeyboardInterrupt:
pass
 
J

John Machin

I parsed that "should" as "this should be changed".


Actually, to allow it through would require re-raising it:

except KeyboardInterrupt:
raise

Yes, I think that's what Geoff is saying "should" be done :)

And all of what he was saying or not saying or should have been saying
was prefaced by "I imagine" anyway :)
 
G

geoffbache

Ben is correct in his interpretation of what I'm trying to say. The
code "should surely be changed" so that it lets a KeyboardInterrupt
exception through.

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top