views:

49

answers:

1

I am creating a mapping application that uses a WSGI service and needs a different config file for each map. Currently, I launch the service with:

import os, sys
tilecachepath = '/usr/local/lib/python2.6/dist-packages/TileCache-2.10-py2.6.egg/TileCache'
sys.path.append(tilecachepath)
from TileCache.Service import Service, wsgiHandler
from paste.request import parse_formvars

theService = {}
def wsgiApp (environ, start_response):
    global theService
    fields = parse_formvars(environ)
    cfgs  = fields['cfg']
    theService = Service.load(cfgs)
    return wsgiHandler(environ, start_response, theService)

application = wsgiApp

This is obviously launching way too many handlers! How can I determine if a specific handler is already running? Is there anything in the apache config that I need to adjust so that handlers time out properly?

+1  A: 

WSGI itself offers no way of knowing what layers are already wrapping a certain application, nor does Apache know about that. I would recommend having the wsgiHandler record its presence, so that you can avoid using it multiple times. If you can't alter the existing code, you can do it with your own wrappers for that code's layer (and use the environment, directly or indirectly, to do the recording of what's already active).

Alex Martelli