Reputation: 217
Let's say I am stepping through code with Eclipse's PyDev.
Is there a way to add some new code below the breakpoint... modify the code on the fly / at runtime?
Upvotes: 4
Views: 1714
Reputation: 1118
I found interesting project on github: pyrasite
Inject code into running Python processes http://pyrasite.com
Upvotes: 1
Reputation: 64837
In PDB, you can use p to evaluate and print expressions and ! to execute atements:
p expression
Evaluate the expression in the current context and print its value.
[!]statement
Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command. To set a global variable, you can prefix the assignment command with a global command on the same line, e.g.:
(Pdb) global list_options; list_options = ['-l']
(Pdb)
Docs: https://docs.python.org/2/library/pdb.html
As for how to do this in PyDev, I don't use PyDev so I'm not quite sure; but this functionality should be available to any BDB-based debuggers (which I believe PyDev is also based on BDB?).
Upvotes: 0