[mod_python] Handler publisher with multiple directories on thesame tree

Mike Looijmans mike.looijmans at asml.com
Mon Sep 8 15:40:26 EST 2003


> When I'm developing I usually have a common problem that is when I
> change a class or some file, sometimes the interpreter remains in memory
> the old version and doesn't load the new one. Is there a way to solve
> this out ? Normally I use an non elegant way, I restart apache!

I use the "reload" built-in function. This loads an internal module from
disk.
My main handler checks if the path_info of the URL is "/request" and if so,
runs the following (you could use publisher to publish this interface as
well).
All "my" modules are named "ops_" something. You could also use the __file__
location as a filter.

def reloadmodules(req):
    '''Try to reload all ops_ modules. This is typically done after updating
    imported scripts, such as ops_cgisql.py. The main scripts will be
    reloaded automatically on demand, so that there is no need to send
    a reload after changing ops_webrellist.py or so.
    This also throws away old DB connections. If there are currently
    active connections, these are preserved.'''
    req.content_type='text/plain'
    # Reload python modules
    modules = sys.modules.keys()
    modules.sort()
    for module in modules:
        if module[:4] == 'ops_':
            try:
                req.write('Reloading: %s\n' % module)
                reload(sys.modules[module])
            except:
                req.write('%s: %s\n' % sys.exc_info()[:2])
    # throw away DB connection objects
    req.write('Destroy DB cached connections\n')
    _lock.acquire()
    try:
        dblist.clear()
    finally:
        _lock.release()
    req.write('Done\n')





-- 
The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.




More information about the Mod_python mailing list