##// END OF EJS Templates
Add a note about the conflict winpdb causes with PyTables.
Fernando Perez -
Show More
@@ -1,73 +1,83
1 """ Debug a script (like %run -d) in IPython process, Using WinPdb
1 """ Debug a script (like %run -d) in IPython process, Using WinPdb
2
2
3 Usage:
3 Usage:
4
4
5 %wdb test.py
5 %wdb test.py
6 run test.py, with a winpdb breakpoint at start of the file
6 run test.py, with a winpdb breakpoint at start of the file
7
7
8 %wdb pass
8 %wdb pass
9 Change the password (e.g. if you have forgotten the old one)
9 Change the password (e.g. if you have forgotten the old one)
10
11
12 Notes
13 -----
14
15 **WARNING**: As of March 2009 (IPython 0.10), WinPdb has a known bug, which
16 causes PyTables to become impossible to import if winpdb is loaded. Therefore,
17 if you need PyTables, do *not* use this extension.
18
19 For more details: https://bugs.launchpad.net/ipython/+bug/249036
10 """
20 """
11
21
12 import os
22 import os
13
23
14 import IPython.ipapi
24 import IPython.ipapi
15 import rpdb2
25 import rpdb2
16
26
17 ip = IPython.ipapi.get()
27 ip = IPython.ipapi.get()
18
28
19 rpdb_started = False
29 rpdb_started = False
20
30
21 def wdb_f(self, arg):
31 def wdb_f(self, arg):
22 """ Debug a script (like %run -d) in IPython process, Using WinPdb
32 """ Debug a script (like %run -d) in IPython process, Using WinPdb
23
33
24 Usage:
34 Usage:
25
35
26 %wdb test.py
36 %wdb test.py
27 run test.py, with a winpdb breakpoint at start of the file
37 run test.py, with a winpdb breakpoint at start of the file
28
38
29 %wdb pass
39 %wdb pass
30 Change the password (e.g. if you have forgotten the old one)
40 Change the password (e.g. if you have forgotten the old one)
31
41
32 Note that after the script has been run, you need to do "Go" (f5)
42 Note that after the script has been run, you need to do "Go" (f5)
33 in WinPdb to resume normal IPython operation.
43 in WinPdb to resume normal IPython operation.
34 """
44 """
35
45
36 global rpdb_started
46 global rpdb_started
37 if not arg.strip():
47 if not arg.strip():
38 print __doc__
48 print __doc__
39 return
49 return
40
50
41 if arg.strip() == 'pass':
51 if arg.strip() == 'pass':
42 passwd = raw_input('Enter new winpdb session password: ')
52 passwd = raw_input('Enter new winpdb session password: ')
43 ip.db['winpdb_pass'] = passwd
53 ip.db['winpdb_pass'] = passwd
44 print "Winpdb password changed"
54 print "Winpdb password changed"
45 if rpdb_started:
55 if rpdb_started:
46 print "You need to restart IPython to use the new password"
56 print "You need to restart IPython to use the new password"
47 return
57 return
48
58
49 path = os.path.abspath(arg)
59 path = os.path.abspath(arg)
50 if not os.path.isfile(path):
60 if not os.path.isfile(path):
51 raise IPython.ipapi.UsageError("%%wdb: file %s does not exist" % path)
61 raise IPython.ipapi.UsageError("%%wdb: file %s does not exist" % path)
52 if not rpdb_started:
62 if not rpdb_started:
53 passwd = ip.db.get('winpdb_pass', None)
63 passwd = ip.db.get('winpdb_pass', None)
54 if passwd is None:
64 if passwd is None:
55 import textwrap
65 import textwrap
56 print textwrap.dedent("""\
66 print textwrap.dedent("""\
57 Winpdb sessions need a password that you use for attaching the external
67 Winpdb sessions need a password that you use for attaching the external
58 winpdb session. IPython will remember this. You can change the password later
68 winpdb session. IPython will remember this. You can change the password later
59 by '%wpdb pass'
69 by '%wpdb pass'
60 """)
70 """)
61 passwd = raw_input('Enter new winpdb session password: ')
71 passwd = raw_input('Enter new winpdb session password: ')
62 ip.db['winpdb_pass'] = passwd
72 ip.db['winpdb_pass'] = passwd
63
73
64 print "Starting rpdb2 in IPython process"
74 print "Starting rpdb2 in IPython process"
65 rpdb2.start_embedded_debugger(passwd, timeout = 0)
75 rpdb2.start_embedded_debugger(passwd, timeout = 0)
66 rpdb_started = True
76 rpdb_started = True
67
77
68 rpdb2.set_temp_breakpoint(path)
78 rpdb2.set_temp_breakpoint(path)
69 print 'It is time to attach with WinPdb (launch WinPdb if needed, File -> Attach)'
79 print 'It is time to attach with WinPdb (launch WinPdb if needed, File -> Attach)'
70 ip.magic('%run ' + arg)
80 ip.magic('%run ' + arg)
71
81
72
82
73 ip.expose_magic('wdb', wdb_f)
83 ip.expose_magic('wdb', wdb_f)
General Comments 0
You need to be logged in to leave comments. Login now