[Tutor] Modifying Source Code while Program is Running

Ed Singleton singletoned at gmail.com
Thu Nov 24 15:26:06 CET 2005


On 24/11/05, Kent Johnson <kent37 at tds.net> wrote:
> Ed Singleton wrote:
> > Is it feasible to change a program's source code whilst it is running
> > without having to restart the program?  Is it feasible to get a
> > program to change it's own source code while it is running?
> >
> > For example, if you have a web server such as CherryPy that will
> > (hopefully) be running for months at a time and you want to be able to
> > change classes without having to restart the server.  Or if you want
> > to allow users of the site to edit a class through the web and see the
> > changes to the site immediately?
>
> This is hard. IIRC CherryPy has a way to automatically restart the server when a module changes, which is not what you ask for but at least it is automatic. A couple of recent threads on comp.lang.python have talked about this:
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/8bb4efbe726c4ab5/848860f76210be69
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/7b34c30c5833a9b0/4ed71bb7c5a97b57
>
> Kent

Hmmm, that's discouraging.  Do you know if it's feasible to just keep
changes to code in memory synchronised with changes nto the source
code?  So rather than reload source code, make sure that the source
code reflects what is running in memory?

For example if your program is running, and you make a change to a
class, is it possible to create the necessary class definition and
save it to a file?

Ed


More information about the Tutor mailing list