pudb icon indicating copy to clipboard operation
pudb copied to clipboard

pudb does not autoreload file in ipython

Open pmcao opened this issue 11 years ago • 8 comments

Hi there,

When using pudb with ipython, e.g.,

%pudb test.py

It does not automatically reload the file when I edit the file using external editors. Could you please suggest a fix? Thanks.

pmcao avatar Feb 08 '14 03:02 pmcao

It's not clear to me why it wouldn't work. It uses execfile (exec in Python 3), which should reload the file if it's changed.

asmeurer avatar Feb 08 '14 07:02 asmeurer

Ah, I see the issue. The file is reloaded, but the display is cached against the old version. But if you step through the file you'll see that it really is running the new version. So the display needs to be refreshed.

asmeurer avatar Feb 08 '14 07:02 asmeurer

Just call linecache.clearcache() at the right moment. That's where pudb gets its source code.

inducer avatar Feb 08 '14 16:02 inducer

What would be the right moment? I tried adding it at https://github.com/inducer/pudb/blob/master/pudb/debugger.py#L370, but that didn't work.

asmeurer avatar Feb 10 '14 02:02 asmeurer

i am facing the same problem. The file seemed to be cached. Only when i load a different file and then load the same one, then it is being reloaded.

hendrics avatar Jun 16 '14 19:06 hendrics

Are there follow-ups to this issue, or ways in which I can contribute to help with the problem? It's a critical feature for me. I use IPython + pudb because my workload usually involves a compute-heavy init step. I use IPython to cache that state, so that working across sessions/edits is fast.

w-hc avatar Sep 03 '23 17:09 w-hc

This could be as simple as calling linecache.clearcache upon entry to the debugger. A PR that does that (with an explanatory comment) would be welcome, if that solves the problem for you all.

inducer avatar Sep 03 '23 17:09 inducer

I wonder if clearing the whole cache could have unindented consequences. Could we clear just the cache for the given file?

asmeurer avatar Sep 03 '23 20:09 asmeurer