durusmail: quixote-users: rtemplate: utility for reloading changed PTL files
rtemplate: utility for reloading changed PTL files
2003-12-06
Re: rtemplate: utility for reloading changed PTL files
2003-12-06
2003-12-06
2003-12-06
2003-12-06
Re: rtemplate: utility for reloading changed PTL files
2003-12-07
Re: rtemplate: utility for reloading changed PTL files
2003-12-07
Re: rtemplate: utility for reloading changed PTL files
2003-12-08
2003-12-07
2003-12-08
2003-12-06
Re: rtemplate: utility for reloading changed PTL files
2003-12-08
Re: rtemplate: utility for reloading changed PTLfiles
2003-12-08
2003-12-08
rtemplate: utility for reloading changed PTL files
Neil Schemenauer
2003-12-08
On Sat, Dec 06, 2003 at 01:18:38AM -0500, Graham Fawcett wrote:
> Attached is a utility module that lets you "wrap" a PTL module in a proxy
> that will reload itself automatically if the source file changes.

If you use 'from ... import ...' then just reloading the module
doesn't work too well.  This is what I have been using:

    def reload_module(fullname):
        module = sys.modules[fullname]
        old_items = module.__dict__.items()
        reload(module)
        objects = {} # [(old_id, new_object)]
        for name, value in old_items:
            if name in module.__dict__:
                if name.startswith('_'):
                    continue
                new_value = module.__dict__[name]
                if new_value is not value:
                    objects[id(value)] = new_value
        for module in sys.modules.values():
            if not hasattr(module, '__dict__'):
                continue
            for name, value in module.__dict__.items():
                if id(value) in objects:
                    print 'updating', getattr(module, '__name__'), name
                    setattr(module, name, objects[id(value)])
        objects.clear()

To use it, I created a form that takes 'fullname' as a query string.
I have my editor configured to that hitting a key causing the module
I'm currently editing to be reloaded.  It's not perfect but seems to
work okay.

  Neil


reply