[wingide-users] Auto-launching wing on exception

Tony Cappellini cappy2112 at gmail.com
Wed Sep 27 18:22:39 MDT 2006


I've just come across this snippet in the Python Cookbook.

***This is NOT my recipe***
(but I"m going to use it a lot) :-)

Put this snippet in c:\Pythonxx\lib\site.py


import sys

def info(type, value, tb):
   if hasattr(sys, 'ps1') or not sys.stderr.isatty():
      # 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
      import 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


If you are not already running pdb, and if you are running from the command
line
pdb will launch and stop so you can debug your exception




Changing it to this, makes it work with the pywin debugge, which is only
marginally better than pdb.

# python cookbook recipe
import sys

def info(type, value, tb):
   if hasattr(sys, 'ps1') or not sys.stderr.isatty():
      # 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
      import pywin.debugger
      # instead of: import pdb pdb.pm() use: import pywin.debugger
pywin.debugger.pm()
      # we are NOT in interactive mode, print the exception...
      traceback.print_exception(type, value, tb)
      print
      # ...then start the debugger in post-mortem mode.
      pywin.debugger.pm()

sys.excepthook = info



Does wing have a mechanism to launch it at the point of the exception, if it
is not already running?
This could be a really usefull feature, especially if you have to step
through many lines of code to get to your exception, or
can't reproduce the exception by stepping through the code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/wingide-users/attachments/20060927/6345fec7/attachment.html


More information about the wingide-users mailing list