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

M

mrstevegross

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
 
J

Jean-Michel Pichavant

mrstevegross said:
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
 
M

mrstevegross

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
 
J

Jeff McNeil

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
 
M

mrstevegross

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
 
J

Jean-Michel Pichavant

mrstevegross said:
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
 

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

No members online now.

Forum statistics

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

Latest Threads

Top