File: sysexcepthook.py

package info (click to toggle)
boa-constructor 0.4.4cvs20050714-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,080 kB
  • ctags: 9,175
  • sloc: python: 56,189; sh: 545; makefile: 40
file content (40 lines) | stat: -rw-r--r-- 1,062 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""

This script allows you to import, start and hook a DebugServer when
an uncaught exception occurs.

Once the DebugServer has started, you may connect to it via 
Tools->Attach to debugger

To use, fix path_to_boa to point to your Boa installation, copy it anywhere
on your sys.path (site-packages is recommended) and import this module.

You may consider importing this module in sitecustomize.py (create it if needed)
if you use it often.

"""

path_to_boa = 'c:/path/to/boa'

import sys, traceback

def hook_debugger(tpe, val, tb):
    traceback.print_exception(tpe, val, tb)
    
    #if sys.modules.has_key('wxPython.wx'):
    import wx
    if wx.MessageBox('%s: %s\n\nStart DebugServer?'%(tpe, val), 
          'Uncaught Exception', wx.ICON_ERROR | wx.YES_NO) == wx.NO:
        return

    if not hasattr(sys, 'debugger_control'):
        sys.path.append(path_to_boa)
        from Debugger.RemoteServer import start

        start(username='', password='')

    sys.debugger_control.post_mortem( (tpe, val, tb) )

sys.excepthook = hook_debugger