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