Edit and continue for debugging?

Jonathan Gardner jgardner at jonathangardner.net
Sat Mar 8 01:31:08 CET 2008

This is an interesting issue because we who write web applications
face the same problem. Except in the web world, the application state
is stored in the browser so we don't have to work our way back to
where we were. We just keep our url, cookies, and request parameters

Before I go on, I would suggest one thing: unit tests. If you have a
hard time writing unit tests, then you need to rethink your code so
that you can write unit tests. Having unit tests, running them, and
debugging them is a far easier way to catch bugs and prevent them from
coming back. If you don't know what a "regression test" is, you should
look into the field of software testing. You'll thank yourself for it.

I'm no lisp programmer, but my understanding of how lisp and lisp-like
programs do this is that they replace the function with the new
version. What this does to threads that are already running the
function, I guess they just finish and continue on. What about
closures? Well, you're out of luck there. I guess lisp programmers
don't use closures in that way too often.

I guess you could do the same in your debug session, although it would
be hacky and difficult at best. You're out of luck if there's more
than a handful of things referring to the object.

A better solution would probably be to fix the offending line in the
offending file and somehow magically reload that file. Well, you still
have the same problem. See, a lot of your program depends on the
functions and classes and objects already in that file. Those
dependencies don't get magically fixed to point to the new objects
just loaded. You'll have to go throughout the entire universe of
variables and make them point to the new stuff. This is not an easy
feat to do.

In the end, you're going to realize that unless you design the system
to allow you to "reload" files, whatever that means (and you'll have
to define that as well), you aren't going to be able to do that. There
just isn't a straightforwad, one-size-fits-all solution to this
problem, except for stopping the process altogether and restarting
from scratch.

On Mar 7, 6:44 am, "Bronner, Gregory" <gregory.bron... at lehman.com>
> I haven't seen much on this for a few years:
> I'm working on a GUI application that has lots of callbacks. Testing it
> is very slow and quite boring, as every time I find an error, I have to
> exit it, restart it, and repeat the series of clicks. It would be really
> amazing if python supported a reasonable form of edit and continue.
> Is there any way to do this? I'd like to be able to change my code and
> have it apply to a running instance of a class. I wonder if it would be
> possible to do this by configuring the interpreter to parse classes and
> functions rather than whole modules, and to re-parse as necessary; also
> to have byte-compiled modules be singletons rather than be standard
> reference counted objects.

More information about the Python-list mailing list