PythonEnablePdb option.

2005-11-03 Thread Graham Dumpleton

The documentation for the Python debugger support in mod_python states:

  Because pdb is an interactive tool, start httpd from the command line
  with the -DONE_PROCESS option when using this directive. As soon as  
your
  handler code is entered, you will see a Pdb prompt allowing you to  
step

  through the code and examine variables.

If you enable PythonEnablePdb but try to use Apache in its normal mode,
ie., not as a single foreground process, you will get an error:

  Mod_python error: PythonHandler mptest

  Traceback (most recent call last):

File  
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
python2.3/site-packages/mod_python/apache.py, line 301, in  
HandlerDispatch

  assert (type(result) == type(int())), \

  AssertionError: Handler 'mptest' returned invalid return code.

This occurs because the pdb module internally generates an error when
it somehow realises that it isn't being run in interactive mode. Rather
than this exception being propagated, it simply returns None which
causes the above error.

Even if running pdb in single process mode, if quit is entered into
pdb as a command, you will get a similar error.

With the thought of mod_python perhaps ignoring the PythonEnabledPdb
option when not run in single process mode, is there a way using the
apache.mpm_query() function or some other function of determining that
Apache is running in single process mode?

This will not solve the quit problem, for that rather than calling
pdb.runcall(), mod_python perhaps could implement an alternate variant  
of

the Bdb.runcall() which is ultimately called which raises an appropriate
Apache error more appropriate in context of mod_python when the BdbQuit
exception is raised.

Anyone have any thoughts? Anyone use the pdb support?

Graham



Re: PythonEnablePdb option.

2005-11-03 Thread Gregory (Grisha) Trubetskoy


On Thu, 3 Nov 2005, Graham Dumpleton wrote:


With the thought of mod_python perhaps ignoring the PythonEnabledPdb
option when not run in single process mode, is there a way using the
apache.mpm_query() function or some other function of determining that
Apache is running in single process mode?


I wonder if simply examining sys.argv would work?

Grisha


Re: PythonEnablePdb option.

2005-11-03 Thread Graham Dumpleton
Graham Dumpleton wrote ..
 Grisha wrote ..
  
  On Thu, 3 Nov 2005, Graham Dumpleton wrote:
  
   With the thought of mod_python perhaps ignoring the PythonEnabledPdb
   option when not run in single process mode, is there a way using the
   apache.mpm_query() function or some other function of determining that
   Apache is running in single process mode?
  
  I wonder if simply examining sys.argv would work?
 
 Can't be done this way as sys.argv doesn't even exist in mod_python.

 ...
 
 Also need to sort out how -DONE_PROCESS and -X options are
 different, as pdb support also works if -X option is used. This is
 probably dangerous though to use as you still potentially get
 child processes and thus fire off more than one request and they
 will fight over standard input.

To determine if -DONE_PROCESS was used on the command line,
noting that -X is equivalent to -DONE_PROCESS and -DNO_DETATCH,
one can use in the Apache configuration file:

  IfDefine ONE_PROCESS
  PythonEnablePdb On
  /IfDefine

As far as I can tell, the IfDefine directive uses the Apache C function:

  ap_exists_config_define()

Ie., the defined symbol is the argument:

  ap_exists_config_define(ONE_PROCESS)

Unless I am missing something, there is no equivalent to being able
to do IfDefine from within Python code executing inside of mod_python.
It sounds though that in this case with pdb that it might be a potentially
useful feature.

Thus, what do people think about a new function:

  apache.exists_config_define(arg)

Graham