I'm writing a simple test program in python3.1 using wsgi, and want to see output from my print statements, for debug purposes. Standard output (stdout) is disabled by default in wsgi due to conflicts with some frameworks, and I tried to turn it back on by a line in the Apache conf file. This should be OK since I'm not using any framework (and only need this output temporarily).
The program works fine on my local shell, and does run on Webfactional with ssh. But the only print output is from print statements that are executed before the server starts. To explore this further, I started the server with an immediate print, followed by a 2-second delay, and the print message "got to application" never appeared (although the delay did occur):
def application(environ, start_response): print("got to application") sleep(2)
To configure Apache to allow standard output, I edited the httpd.conf file at /home/replicounts/webapps/replicounts/apache2/conf adding one line (the 'Off' below):
WSGILazyInitialization On WSGIRestrictStdout OffThis did not cause any visible change.
Pehaps the problem is that unlike with the local shell, the Webfactional ssh shell returns immediately to the command line, once the server starts:
test1 test2 test Sun, 16 Oct 2011 19:31 [replicounts@web214 htdocs]$The first 3 lines were printed by my program before the server started, so I know that the program is being run. But the "got to application" message never appears. It wouldn't make much sense for that message to come out after return to the shell prompt. If this is the problem, is there any way to avoid returning immediately to the shell, to let the debug printouts appear instead?
I could redirect stdout to the stderr output and see it in the logs, but watching the printouts as they happen would be better. Any suggestions appreciated.
asked Oct 16 '11 at 20:01
I have not tested this in python3, but why not just print to sys.stderr?
This will put the output in the error logs in ~/logs/ and can be tailed to produce an effect similar to the local django dev server,
Why the wsgi directive is not working is harder to say. The documentation seems to suggest you have to send it to either stdout or stderror specifically as in the above example.
You may want to look at this document which covers debug options for WSGI.