Show More
@@ -0,0 +1,73 b'' | |||
|
1 | """ Debug a script (like %run -d) in IPython process, Using WinPdb | |
|
2 | ||
|
3 | Usage: | |
|
4 | ||
|
5 | %wdb test.py | |
|
6 | run test.py, with a winpdb breakpoint at start of the file | |
|
7 | ||
|
8 | %wdb pass | |
|
9 | Change the password (e.g. if you have forgotten the old one) | |
|
10 | """ | |
|
11 | ||
|
12 | import os | |
|
13 | ||
|
14 | import IPython.ipapi | |
|
15 | import rpdb2 | |
|
16 | ||
|
17 | ip = IPython.ipapi.get() | |
|
18 | ||
|
19 | rpdb_started = False | |
|
20 | ||
|
21 | def wdb_f(self, arg): | |
|
22 | """ Debug a script (like %run -d) in IPython process, Using WinPdb | |
|
23 | ||
|
24 | Usage: | |
|
25 | ||
|
26 | %wdb test.py | |
|
27 | run test.py, with a winpdb breakpoint at start of the file | |
|
28 | ||
|
29 | %wdb pass | |
|
30 | Change the password (e.g. if you have forgotten the old one) | |
|
31 | ||
|
32 | Note that after the script has been run, you need to do "Go" (f5) | |
|
33 | in WinPdb to resume normal IPython operation. | |
|
34 | """ | |
|
35 | ||
|
36 | global rpdb_started | |
|
37 | if not arg.strip(): | |
|
38 | print __doc__ | |
|
39 | return | |
|
40 | ||
|
41 | if arg.strip() == 'pass': | |
|
42 | passwd = raw_input('Enter new winpdb session password: ') | |
|
43 | ip.db['winpdb_pass'] = passwd | |
|
44 | print "Winpdb password changed" | |
|
45 | if rpdb_started: | |
|
46 | print "You need to restart IPython to use the new password" | |
|
47 | return | |
|
48 | ||
|
49 | path = os.path.abspath(arg) | |
|
50 | if not os.path.isfile(path): | |
|
51 | raise IPython.ipapi.UsageError("%%wdb: file %s does not exist" % path) | |
|
52 | if not rpdb_started: | |
|
53 | passwd = ip.db.get('winpdb_pass', None) | |
|
54 | if passwd is None: | |
|
55 | import textwrap | |
|
56 | print textwrap.dedent("""\ | |
|
57 | 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 | |
|
59 | by '%wpdb pass' | |
|
60 | """) | |
|
61 | passwd = raw_input('Enter new winpdb session password: ') | |
|
62 | ip.db['winpdb_pass'] = passwd | |
|
63 | ||
|
64 | print "Starting rpdb2 in IPython process" | |
|
65 | rpdb2.start_embedded_debugger(passwd, timeout = 0) | |
|
66 | rpdb_started = True | |
|
67 | ||
|
68 | rpdb2.set_temp_breakpoint(path) | |
|
69 | print 'It is time to attach with WinPdb (launch WinPdb if needed, File -> Attach)' | |
|
70 | ip.magic('%run ' + arg) | |
|
71 | ||
|
72 | ||
|
73 | ip.expose_magic('wdb', wdb_f) |
General Comments 0
You need to be logged in to leave comments.
Login now