Changeset 41
- Timestamp:
- 02/11/06 00:05:14
- Files:
-
- modpython_gateway.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modpython_gateway.py
r39 r41 7 7 <Location /mcontrol> 8 8 SetHandler python-program 9 PythonFixupHandler mcontrol.cherry::startup 9 10 PythonHandler modpython_gateway::handler 10 PythonOption application cherrypy._cpwsgi::wsgiApp 11 PythonOption import mcontrol.cherry::startup 11 PythonOption wsgi.application cherrypy._cpwsgi::wsgiApp 12 12 </Location> 13 13 … … 164 164 165 165 166 _counter = 0167 168 def profile(req):169 # Call this function instead of "handler"170 # to get profiling data for each call.171 import hotshot, os.path172 global _counter173 _counter += 1174 ppath = os.path.join(os.path.dirname(__file__), "cp_%s.prof" % _counter)175 prof = hotshot.Profile(ppath)176 prof.runcall(handler, req)177 prof.close()178 return apache.OK179 180 166 def handler(req): 181 # If you use a PythonImport directive as recommended, its interpreter_name182 # value must EXACTLY match the value of req.interpreter (case-sensitive).183 # You can un-comment the next line to get the value of req.interpreter.184 ## raise StandardError(repr(req.interpreter))185 186 config = req.get_config()187 debug = int(config.get("PythonDebug", 0))188 189 options = req.get_options()190 191 # Because PythonImport cannot be specified per Directory or Location,192 # take any 'import' PythonOption's and import them. If a function name193 # in that module is provided (after the "::"), it will be called with194 # the request as an argument. The module and function, if any, should195 # be re-entrant (i.e., handle multiple threads), and, since they will196 # be called per request, must be designed to run setup code only on the197 # first request (a global 'first_request' flag is usually enough).198 import_opt = options.get('import')199 if import_opt:200 atoms = import_opt.split('::', 1)201 modname = atoms.pop(0)202 module = __import__(modname, globals(), locals(), [''])203 if atoms:204 func = getattr(module, atoms[0])205 func(req)206 207 167 # Import the wsgi 'application' callable and pass it to Handler.run 208 modname, objname = options['application'].split('::', 1)168 modname, objname = req.get_options()['wsgi.application'].split('::', 1) 209 169 module = __import__(modname, globals(), locals(), ['']) 210 170 app = getattr(module, objname)
