Annoying message when interrupting python scripts

Discussion in 'Python' started by geoffbache, Jun 17, 2008.

  1. geoffbache

    geoffbache Guest

    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
     
    geoffbache, Jun 17, 2008
    #1
    1. Advertising

  2. geoffbache

    geoffbache Guest

    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
     
    geoffbache, Jun 17, 2008
    #2
    1. Advertising

  3. geoffbache

    John Machin Guest

    On Jun 18, 12:51 am, geoffbache <> wrote:
    [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
     
    John Machin, Jun 18, 2008
    #3
  4. geoffbache

    John Machin Guest

    On Jun 18, 12:26 pm, Ben Finney <>
    wrote:
    > John Machin <> writes:
    > > On Jun 18, 12:51 am, geoffbache <> wrote:
    > > [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 :)
     
    John Machin, Jun 18, 2008
    #4
  5. geoffbache

    geoffbache Guest

    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
     
    geoffbache, Jun 18, 2008
    #5
  6. geoffbache

    geoffbache Guest

    geoffbache, Jun 19, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kaburke

    Non-Interrupting Logins

    kaburke, Aug 16, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    382
    kaburke
    Aug 18, 2005
  2. Jan Danielsson
    Replies:
    8
    Views:
    666
    Mike Meyer
    Jul 22, 2005
  3. Jp Calderone
    Replies:
    0
    Views:
    480
    Jp Calderone
    Jul 21, 2005
  4. Replies:
    0
    Views:
    328
  5. davidj411
    Replies:
    0
    Views:
    578
    davidj411
    Jun 27, 2008
Loading...

Share This Page