Contact: fumanchu@aminus.org

Log in as guest/misc to create tickets

Changeset 93

Show
Ignore:
Timestamp:
06/07/06 01:09:49
Author:
fumanchu
Message:

New PythonOption? wsgi.cleanup to register cleanup logic.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modpython_gateway.py

    r41 r93  
    1919    PythonOption SCRIPT_NAME /mcontrol 
    2020 
     21Some WSGI applications need to be cleaned up when Apache exits. You can 
     22register a cleanup handler with yet another PythonOption directive: 
     23 
     24    PythonOption wsgi.cleanup module::function 
     25 
     26The module.function will be called with no arguments on server shutdown, 
     27once for each child process or thread. 
    2128""" 
    2229 
     
    164171 
    165172 
     173cleanup = None 
     174 
    166175def handler(req): 
     176    # Register a cleanup function if requested. 
     177    global cleanup 
     178    if not cleanup: 
     179        func = req.get_options().get('wsgi.cleanup') 
     180        if func: 
     181            module_name, object_str = func.split('::', 1) 
     182            module = __import__(module_name, globals(), locals(), ['']) 
     183            object = apache.resolve_object(module, object_str) 
     184            def cleaner(data): 
     185                object() 
     186            apache.register_cleanup(cleaner) 
     187     
    167188    # Import the wsgi 'application' callable and pass it to Handler.run 
    168189    modname, objname = req.get_options()['wsgi.application'].split('::', 1)