[Python-Dev] VERBOSE and DEBUG conventions.

Tim Peters tim.one@home.com
Wed, 23 Jan 2002 12:51:58 -0500


[Steven Majewski]
> Py_DebugFlag is used for debugging the Python parser.

If Guido had it to do over again, I suspect he'd put that code in #ifdef
Py_DEBUG blocks instead.

> Py_VerboseFlag is used for debugging and tracing imports.
>  (and in some places it wants Py_VerboseFlag > 1 (more than one "-v")
>    for output)
>
> Are there any conventions on which to use for other debugging output?

Py_VerboseFlag is for output about core activities every user of Python may
want to see sometimes, and in release builds.  It doesn't cover much beyond
tracing imports, printing stats about memory cleanup, and some highly
dubious fudging:

PyThreadState_Clear(PyThreadState *tstate)
{
	if (Py_VerboseFlag && tstate->frame != NULL)
		fprintf(stderr,
		  "PyThreadState_Clear: warning: thread still has a frame\n");

(that should probably be an error instead -- or be officially blessed).

> (Or did Guido have any particular conventions in mind when he added
> them? )
>
> Right now, I'm using Py_VerboseFlag to also trigger logging of message
> sends in pyobjc. Stealing this flag for another use isn't a problem
> here because [1] the logging goes to a /tmp file, so I don't have
> to turn off import tracing -- the two logging streams don't get mixed
> together, and [2] it only functions when you import pyobjc, so it's
> not going to get in someone else's use.
>
> But I may need to add other debug and log output to my module and
> I'ld like to do it in the least suprising manner if possible.

Supply a "set debug and log options" interface for your module, and then
call it <wink>.  Good example:  the gc module.