WebFaction
Community site: login faq

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 Off
This 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 16 Oct '11, 20:01

replicounts
123
accept rate: 0%


I have not tested this in python3, but why not just print to sys.stderr?

import sys
print >> sys.stderr, 'foo'

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,

tail -f ~/logs/user/error_<app>*

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.

permanent link

answered 16 Oct '11, 20:25

johns
5.4k312
accept rate: 23%

edited 16 Oct '11, 20:27

Thanks. I'm doing essentially the same thing, with: sys.stdout = sys.stderr near the beginning of my application. Minor drawback: I need to go look at the logs to see the error messages.

(20 Oct '11, 19:28) replicounts
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×225
×103
×62
×1

question asked: 16 Oct '11, 20:01

question was seen: 5,568 times

last updated: 20 Oct '11, 19:28

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM