I had a mod_python script I wanted to run, but give the deployer the option whether or not to have an associated module be persistent or not. What this comes down to in the actual script is whether the reference to that module is in the local or global namespace. Every time the script is called, the req object (supplied by mod_python) is queried to see if it has the PythonOption "persist" set. If it does, the aUI object is global; otherwise local. This particular script will show an incrementing counter if persistence is "on", a non-incrementing "counter" if "off" (it stays at 1). [The UIHTML module has a counter() function that you'll just have to take my word for]

from mod_python import apache, util\nfrom endue.interface import UIHTML\n\naUI = None\n\ndef assertUI():\n    global aUI\n    if aUI is None:\n        aUI = UIHTML.InterfaceHTML()\n\ndef handler(req):\n    # Provide for persistent (or not) Interface object\n    if req.get_options().has_key('persist'):\n        global aUI\n        assertUI()\n    else:\n        aUI = UIHTML.InterfaceHTML()\n\n    try:\n        req.write("Counter is %s" % aUI.counter())\n        return apache.OK\n    except:\n        return apache.HTTP_INTERNAL_SERVER_ERROR


edit: cleaned misleading comments