擅长:python、mysql、java
<p>主要取自<a href="http://code.activestate.com/recipes/65287-automatically-start-the-debugger-on-an-exception/">this great snippet</a>:</p>
<pre><code>import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type != AssertionError:
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(type, value, tb)
print
# ...then start the debugger in post-mortem mode.
pdb.pm()
sys.excepthook = info
</code></pre>
<p>当您用这个初始化代码时,所有<code>AssertionError</code>都应该调用pdb。在</p>