#5677: Debugging with mod_python (apache) improperly documented
---------------------------------------------------------------+------------
Reporter: Manfred Wassmann <[EMAIL PROTECTED]> | Owner:
nobody
Status: new |
Component: Documentation
Version: SVN |
Resolution:
Keywords: |
Stage: Accepted
Has_patch: 0 |
Needs_docs: 0
Needs_tests: 0 |
Needs_better_patch: 0
---------------------------------------------------------------+------------
Comment (by grahamd):
If talking about use of 'print', can you strongly discourage use of
'print' without explicitly directing the output to sys.stderr. Ie.,
discourage use of:
{{{
print 'debug text'
}}}
This is because the resulting code is technically not safe to run on all
possible WSGI hosting solutions. This is because some WSGI hosting
solutions, such as CGI, use sys.stdout to communicate with the core web
server. Thus, if users use 'print' without directing it anywhere, the
output from it will interleave with valid output being sent back to the
client and screw up the response.
So, suggest use of:
{{{
print >> sys.stderr, ' debug text'
}}}
if anything.
But then as already pointed out, in mod_python this really needs to be:
{{{
print >> sys.stderr, ' debug text'
sys.stderr.flush()
}}}
What Django developers should perhaps instead consider to get around this,
is in the Django mod_python adapter when it is imported, replace
sys.stderr with a stream like object which buffers data until an EOL is
encountered and then call mod_python.apache.log_error() explicitly. This
will ensure that when sys.stderr is used that output appears promptly, it
will also attach time stamps to each line of output. Note that if the
output passed to the dummy stream object contains embedded EOL, then the
line should be split and passed to log_error() one line at a time though.
By doing this sys.stderr replacement, it would avoid all these problems
with output not appearing in Apache log in a timely manner. Although one
could replace sys.stdout as well, as I said you probably want to
discourage people outputing to sys.stdout directly or indirectly.
--
Ticket URL: <http://code.djangoproject.com/ticket/5677#comment:2>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---