By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

Annoying message when interrupting python scripts

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a

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
Jun 27 '08 #2

P: n/a
On Jun 18, 12:51 am, geoffbache <geoff.ba...@jeppesen.comwrote:
[snip]
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
Jun 27 '08 #3

P: n/a
John Machin <sj******@lexicon.netwrites:
On Jun 18, 12:51 am, geoffbache <geoff.ba...@jeppesen.comwrote:
[snip]
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.
I parsed that "should" as "this should be changed".
Allowing a KeyboardInterrupt exception through would require:
except KeyboardInterrupt:
pass
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 :-)

--
\ "When I was born I was so surprised I couldn't talk for a year |
`\ and a half." -- Gracie Allen |
_o__) |
Ben Finney
Jun 27 '08 #4

P: n/a
On Jun 18, 12:26 pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
John Machin <sjmac...@lexicon.netwrites:
On Jun 18, 12:51 am, geoffbache <geoff.ba...@jeppesen.comwrote:
[snip]
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.

I parsed that "should" as "this should be changed".
Allowing a KeyboardInterrupt exception through would require:
except KeyboardInterrupt:
pass

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 :-)
Jun 27 '08 #5

P: n/a

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
Jun 27 '08 #6

P: n/a

As nobody decried the idea of this being a bug, it now is :)

http://bugs.python.org/issue3137

/Geoff
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.