0

I am assuming that this question can be generic to pydev, but I have only used pydev in eclipse so I am not sure...

In the past, I have accidentally done this and I would like to learn how to do it regularly:

  1. I was running the breakpoint debugger in eclipse pydev
  2. I had stopped on a line of code and realized that I needed to change something
  3. I made the change to my code
  4. I saved the code
  5. The debugger jumped just before my last change so that I could continue with debug session as and use the new change:
    • as if the old code had never happened

I am not sure how this works, but I would like to understand exactly how to trigger this because it is not happening any more as I debug.

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
Pswiss87
  • 615
  • 1
  • 5
  • 15
  • Just a side note, python code isn't compiled but interpreted. – Jakob Bowyer Jan 24 '13 at 15:12
  • @JakobBowyer Nonsense, there's `.pyc` files for CPython, and `compile()` in the standard library. It sometimes outputs bytecode which is then interpreted (but not always! cf. Nuitka, PyPy's JIT, Cython, and other niche implementation) but that's an implementation detail. –  Jan 24 '13 at 15:23
  • @delnan but you (for the large part) can execute any python code without "compiling" it to bytecode at all, making it a purely interpreted langauge – Jakob Bowyer Jan 24 '13 at 15:32
  • 2
    No language is compiled or interpreted. The interpreter component of CPython is a bytecode interpreter that also accepts source code and transparently compiles it to bytecode, yet. But that doesn't mean the concept of compilation is meaningless (as you imply) -- it's quite important to mind the `compile()` step when dynamically generating Python code in memory, for example. It also affects what introspection capabilities are available (functions only have a `__code__` attribute, they don't carry around source code). But yes, OP is actually concerned with dynamically *replacing* code. –  Jan 24 '13 at 15:36

1 Answers1

0

Well, there are some facets to this:

If you're using a framework (such as Django), it has reload support builtin, so, you'll get code-changes on the fly (usually by spawning a new process).

Now if this is not the case, in the latest PyDev versions, PyDev will keep track of editions done to the code and will attempt to 'hot-swap' the old code for the new code.

It's based on xreload and will try to patch classes in runtime (i.e.: changing classes/methods code directly).

The only thing to note is that it'll only take effect if you leave the given function and come back to it again later on because Python has no way of patching the code on a running frame (and sometimes it may not succeed into doing the swapping depending on how the code is constructed, but for the common cases it does work well).

Note that this is only available in the latest PyDev versions. It was on some earlier versions but was removed because of issues in its implementation -- but had a revamp and is re-added back :)

See: http://pydev.org/manual_adv_debugger_auto_reload.html for more details.

Fabio Zadrozny
  • 23,566
  • 4
  • 60
  • 73