What is the actual type of "interrupted system call"?

Discussion in 'Python' started by mrstevegross, Jun 9, 2009.

  1. mrstevegross

    mrstevegross Guest

    I'm trying to write a try/catch block to handle an "interrupted system
    call". However, I can't seem to locate information on the actual
    typename of the exception. Does anyone know what it would be? I want
    my code to look like this:

    try:
    ...
    except InterruptedSystemCall # what's the right name?
    ...


    Thanks,
    --Steve
    mrstevegross, Jun 9, 2009
    #1
    1. Advertising

  2. mrstevegross wrote:
    > I'm trying to write a try/catch block to handle an "interrupted system
    > call". However, I can't seem to locate information on the actual
    > typename of the exception. Does anyone know what it would be? I want
    > my code to look like this:
    >
    > try:
    > ...
    > except InterruptedSystemCall # what's the right name?
    > ...
    >
    >
    > Thanks,
    > --Steve
    >

    pick up your choice:

    exceptions.ArithmeticError exceptions.OSError
    exceptions.UnicodeTranslateError
    exceptions.AssertionError exceptions.OverflowError exceptions.UserWarning
    exceptions.AttributeError exceptions.OverflowWarning exceptions.ValueError
    exceptions.DeprecationWarning exceptions.PendingDeprecationWarning
    exceptions.Warning
    exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError
    exceptions.EnvironmentError exceptions.RuntimeError exceptions.__class__
    exceptions.Exception exceptions.RuntimeWarning exceptions.__delattr__
    exceptions.FloatingPointError exceptions.StandardError exceptions.__dict__
    exceptions.FutureWarning exceptions.StopIteration exceptions.__doc__
    exceptions.IOError exceptions.SyntaxError exceptions.__getattribute__
    exceptions.ImportError exceptions.SyntaxWarning exceptions.__hash__
    exceptions.IndentationError exceptions.SystemError exceptions.__init__
    exceptions.IndexError exceptions.SystemExit exceptions.__name__
    exceptions.KeyError exceptions.TabError exceptions.__new__
    exceptions.KeyboardInterrupt exceptions.TypeError exceptions.__reduce__
    exceptions.LookupError exceptions.UnboundLocalError exceptions.__reduce_ex__
    exceptions.MemoryError exceptions.UnicodeDecodeError exceptions.__repr__
    exceptions.NameError exceptions.UnicodeEncodeError exceptions.__setattr__
    exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__

    CTRL+C (SIG_INT) is KeyboardInterrupt

    Jean-Michel
    Jean-Michel Pichavant, Jun 9, 2009
    #2
    1. Advertising

  3. mrstevegross

    mrstevegross Guest

    > exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError
    >...
    > exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__


    Is there a single parent exception to all those? Or should I just
    write it as:

    try:
    ...
    catch Exception:
    ...

    Thanks,
    --Steve
    mrstevegross, Jun 9, 2009
    #3
  4. mrstevegross

    Jeff McNeil Guest

    On Jun 9, 2:22 pm, mrstevegross <> wrote:
    > I'm trying to write a try/catch block to handle an "interrupted system
    > call". However, I can't seem to locate information on the actual
    > typename of the exception. Does anyone know what it would be? I want
    > my code to look like this:
    >
    > try:
    >   ...
    > except InterruptedSystemCall # what's the right name?
    >   ...
    >
    > Thanks,
    > --Steve


    You'll get that error when an async. event (signal) is delivered to
    your application during a system call. It's a result of 'errno' being
    set to errno.EINTR (4). I check for a few such specific conditions in
    some of my code and I usually do it like so:

    try:
    .....
    except EnvironmentError, e:
    if e.errno == errno.EINTR:
    do_something_with_eintr_error()
    else:
    raise

    That works for me. There isn't an "InterruptedSystemCall" error or
    equivalent in the standard exception hierarchy. EnvironmentError is
    the parent of OSError & IOError, which is where you'll most likely be
    encountering that state.

    Thanks,

    Jeff
    mcjeff.blogspot.com
    Jeff McNeil, Jun 9, 2009
    #4
  5. mrstevegross

    mrstevegross Guest

    > That works for me.  There isn't an "InterruptedSystemCall" error or
    > equivalent in the standard exception hierarchy.  EnvironmentError is
    > the parent of OSError & IOError, which is where you'll most likely be
    > encountering that state.


    Thanks!
    --Steve
    mrstevegross, Jun 9, 2009
    #5
  6. mrstevegross wrote:
    >> exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError
    >> ...
    >> exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__
    >>

    >
    > Is there a single parent exception to all those? Or should I just
    > write it as:
    >
    > try:
    > ...
    > catch Exception:
    > ...
    >
    > Thanks,
    > --Steve
    >

    You're right, Exception is the parent of (almost) all exceptions.
    I wouldn't advise writing such block catching all exceptions, it makes
    error tracking quite difficult. However if you don't know the type of
    exception involved in a particular case, you can write

    try:
    ....
    except Exception, excInstance:
    print excInstance.__class__.__name__
    print excInstance.__dict__

    If you know how to trigger the exception, it should print the class name
    of the exception, along with its attributes. It will help you then write
    a more focused except clause.

    Jean-Michel
    Jean-Michel Pichavant, Jun 10, 2009
    #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. Jakub Moscicki
    Replies:
    2
    Views:
    543
    Jakub Moscicki
    Oct 4, 2003
  2. Marco
    Replies:
    0
    Views:
    735
    Marco
    Feb 6, 2007
  3. Marco
    Replies:
    7
    Views:
    4,502
    Gabriel Genellina
    Feb 17, 2007
  4. Gabriel Genellina

    Re: IOError: [Errno 4] Interrupted system call

    Gabriel Genellina, Feb 7, 2007, in forum: Python
    Replies:
    0
    Views:
    470
    Gabriel Genellina
    Feb 7, 2007
  5. Rainy
    Replies:
    1
    Views:
    826
    Vinay Sajip
    Dec 7, 2008
Loading...

Share This Page