Want to monitor process..

Peter Hansen peter at engcorp.com
Fri Mar 1 06:31:55 EST 2002


Stephen wrote:
> 
> > Yikes!  "Crash"?  Do you really mean they crash the Python interpreter,
> > or do you mean they exit with an exception?
> 
> Sorry, I guess I mean "exit with an exception" though to be honest, I
> still don't know because I haven't been able to run the programs
> interactively during a 'crash'.  

I'm not sure what the interactive thing would add, since the
interpreter will already print exception tracebacks to the console
whenever your program exits exceptionally.  If you aren't seeing
a traceback, maybe you aren't really exiting with an exception.

> > If the latter, just wrap the highest level code with a try/finally
> > or try/except and put code in to ensure the child processes are
> > properly terminated.  Simple, clean, safe.
> 
> Will do.  I didn't want to put try/except/finally at the highest level
> of code yet since we're actually in Beta and I want to know when my
> server encounters a problem.  

No problem, just put a "raise" statement as the final statement in
the exception handling block (when using try/except only) and you'll
still propagate the exception up and right out of the interpreter
so it prints a traceback to the console.  In the try/finally case,
however, you'll still get the traceback if an exception *did* 
occur, because the interception is only a temporary one.  After the
finally code executes, exception processing continues on.

> Problem has been that not running it in
> interactive mode, I've missed the reasons for the failures.  That's
> why I also asked about logging recently.

Logging is good, but shouldn't be absolutely essential to catch
a serious exception.  The interactive mode should be entirely
unnecessary and, as you suggest, gets in the way of normal
execution.

I think you might focus on the lack of a traceback.  You should
always see one if you aren't explicitly swallowing the exception.
(Note, a few standard modules such as the SocketServer and such
will internally swallow exceptions in the server threads by default.)

-Peter



More information about the Python-list mailing list