[mod_python] i beg the developers to make mod_python can be importin python command line.

Graham Dumpleton grahamd at dscpl.com.au
Tue Aug 15 01:14:31 EDT 2006


guo tie wrote ..
> hi,
>    All
> 
>    These days i was work with mod_python, i found it is difficult to debug
> it , if you can made it be debuged in python command line mode ,
> 
> i think it is a great thing

The closest you will get is to enable the 'PythonEnablePdb' option. See:

  http://www.modpython.org/live/current/doc-html/dir-other-epd.html

Ie., in your Apache configuration pertinent to where your handlers are have:

  PythonEnablePdb On

You then need to run Apache 'httpd' explicitly with the '-DONE_PROCESS'
option.

  /usr/local/apache-2.0/bin/httpd -DONE_PROCESS

This runs Apache in single process mode.

Because Apache will try and use its regular listener port, you will need to
have shutdown your regular Apache instance first to do this.

With this option on, when a request comes in that triggers your request,
you will be thrown into a Python debugger environment. You can then
interact with your running request handler. For example:

~ grahamd$ /usr/local/apache-2.0/bin/httpd -DONE_PROCESS
> /Users/grahamd/public_html/filters/handlers.py(24)handler()
-> req.add_handler('PythonHandler', handler1)
where
  /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/importer.py(960)_execute_target()
-> result = object(arg)
> /Users/grahamd/public_html/filters/handlers.py(24)handler()
-> req.add_handler('PythonHandler', handler1)

print req.filename
/Users/grahamd/public_html/filters/xxx.py

print req.get_options()
{'mod_python.future.importer': 'testing'}

For details on the Python debugger and what it can do, see:

  http://docs.python.org/lib/module-pdb.html

The only other option is to do what some users do, which is to construct
a mini framework which fakes up a request object which emulates the
minimum of what they required for their code to run. This allows them
to do some testing from the command line or using automated test scripts.

Hope this helps.

Graham


More information about the Mod_python mailing list