<font color="#000000"><br></font><br><div class="gmail_quote">On Sun, Apr 10, 2011 at 4:49 PM, Jerry Hill <span dir="ltr"><<a href="mailto:malaclypse2@gmail.com">malaclypse2@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Sun, Apr 10, 2011 at 3:25 PM, Jason Swails <<a href="mailto:jason.swails@gmail.com">jason.swails@gmail.com</a>> wrote:<br>
><br>
> Hello everyone,<br>
><br>
> This may sound like a bit of a strange desire, but I want to change the way in which a python program quits if an exception is not caught.  The program has many different classes of exceptions (for clarity purposes), and they're raised whenever something goes wrong.  Most I want to be fatal, but others I'd want to catch and deal with.<br>

><br>
> Is there any way to control Python's default exit strategy when it hits an uncaught exception (for instance, call another function that exits "differently")?<br>
<br>
</div>When an exception is raised and uncaught, the interpreter calls<br>
sys.excepthook. You can replace sys.excepthook with your own function.<br>
 See <a href="http://docs.python.org/library/sys.html#sys.excepthook" target="_blank">http://docs.python.org/library/sys.html#sys.excepthook</a><br></blockquote><div><br>This is exactly what I was looking for.  Thank you!  I can just redefine sys.excepthook to call MPI's Abort function and print the Tracebacks; exactly what I wanted.<br>
<br>MPI threading doesn't work in the same way as, for instance, the threading modules in Python's stdlib.  It doesn't spawn additional threads from some 'main' thread.  Instead, all of the threads are launched simultaneously at the beginning and run the same program, dividing the workload based on their rank, so I think my application is immune to this bug.<br>
<br>Thanks again!<br>Jason<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
If your program is threaded, you may need to look at this bug:<br>
<a href="http://bugs.python.org/issue1230540" target="_blank">http://bugs.python.org/issue1230540</a>.  It describes a problem with<br>
replacing sys.excepthook when using the threading module, along with<br>
some workarounds.<br>
<br>
There's a simple example of replacing excepthook here:<br>
<a href="http://code.activestate.com/recipes/65287/" target="_blank">http://code.activestate.com/recipes/65287/</a><br></blockquote></div>