Modifying running code? [HACK ALERT]

Michael Hudson mwh21 at cam.ac.uk
Mon Dec 11 10:26:38 EST 2000


Bjoern Giesler <un4e at rzstud1.rz.uni-karlsruhe.de> writes:

> Hi,
> 
> I'm writing a kind of mini runtime environment that lets me debug / correct
> buggy Python code "on the fly". This is supposed to work as follows:
> 
> 1) an exception gets thrown by the buggy code and is caught by a toplevel
> exception handler
> 
> 2) the toplevel handler figures out the function that caused the exception
> 
> 3) the function source is loaded into an editor and can be corrected by the
> user
> 
> 4) if the code has been saved, it is recompiled and inserted instead of the
> original function
> 
> 5) the program is then resumed at the point where the original function had
> been called
> 
> Can this be done in Python at all? Can it be done in regular Python or only
> in Stackless Python (which supports continuations and would therefore, I
> believe, make step 5 easy)? Is the whole thing complete bull doodoo? Any
> hints or suggestions?

You'd certainly have to write some C to get round the fact that frames
are immutable in Python & starting with stackless Python is probably
wise and you'd need to write most of it anyway.

I'm not sure what you're trying to do is particularly wise, but that's
your concern, not mine :-)

Cheers,
M.

-- 
41. Some programming languages manage to absorb change, but 
    withstand progress.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html



More information about the Python-list mailing list