[mod_python] Mod_python & global persistence

Wagner,Harry wagnerh at oclc.org
Mon Mar 7 16:32:27 EST 2005


Is there a way with mod_python to init global variables in a handler the
first time it is called, so that they are available (and already
initialized) in subsequent calls to the handler?  I thought the
following might work, but no joy:

from mod_python import apache, util, Session

def handler(req):
#	req.log_error("in handler")
	global ddcServer
	ddcServer.req = req
	ddcServer.do_GET()
	return apache.OK
...
ddcServer = ''
if not ddcServer:
	...
	ddcServer = DDCServer(None)	
	ddcServer.captions = DDCCaptions(captionsFile)
	ddcServer.localText = TextLocalization(captionsFile)
	ddcServer.ddcSearch = ddc3.DDCSearch(oclc2ddcFile, recFileName,
compFile)

The 'if not ddcServer' code is invoked with every call to the handler.
Any ideas what I am doing wrong, or if this is possible with mod_python?


TIA... harry



More information about the Mod_python mailing list