runserver stdout and stderr piping problems

732 views
Skip to first unread message

JuhaS

unread,
Jan 20, 2012, 3:04:29 PM1/20/12
to Django developers
I was launching manage.py runserver from another app and trying to
capture the output correctly without luck using pipes. Eventually I
narrowed the problem down to two issues. In my opinion they are bugs
but I thought I'd ask for confirmations here before creating a ticket
and patch.

Issue 1: The startup message of development server isn't flushed.

The result is that starting the server from console directly it is
printed correctly during startup, but using pipes the message isn't
flushed until shutdown (Ctrl+C pressed). Since log messages use etderr
(issue 2) they are flushed before the startup message.

Example:

$ python manage.py runserver 2>> output 1>> output // redirect stderr
and stdout to file named output

[send few http requests]
[press Ctrl+C]

$ cat output

[20/Jan/2012 13:54:24] "GET // HTTP/1.1" 200 358
[20/Jan/2012 13:54:24] "GET // HTTP/1.1" 200 358
[20/Jan/2012 13:54:24] "GET // HTTP/1.1" 200 358
Validating models...

0 errors found
Django version 1.4 alpha 1, using settings 'djangotut.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Since the actual log messages go to stderr (next issue), the startup
message keeps hanging until shotdown when it's eventually printed to
end of the file. I tried with many commands and all showed the same
issue.

Is this a clear bug?

SOLUTION: adding a stdout.flush() to runserver.py fixes this for me.


Issue 2: Log entries about http requests go to stderr

For some reason the log entries go to stderr (for example 'GET //
HTTP...'). Is this a bug, or is there some reason for this?

Russell Keith-Magee

unread,
Jan 9, 2013, 8:50:45 PM1/9/13
to django-d...@googlegroups.com

I'm not aware of a ticket for this issue, and I couldn't find one from a quick search, so feel free to open one. The approach described by the OP seems reasonable, so if you want to provide a patch as well, feel free.

Yours,
Russ Magee %-)

On Wed, Jan 9, 2013 at 11:37 PM, Chris Proto <chro...@gmail.com> wrote:
Did you ever get around to opening a ticket for this?  If so, what is the status?
--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/GgVXCHG1e2QJ.

To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.

Chris Proto

unread,
Jan 10, 2013, 2:56:30 PM1/10/13
to django-d...@googlegroups.com

Chris Proto

unread,
Jan 10, 2013, 3:00:04 PM1/10/13
to django-d...@googlegroups.com
It doesn't look like it responded to this topic when I sent a reply with email.

Anyway, I opened up a ticket  https://code.djangoproject.com/ticket/19593
Reply all
Reply to author
Forward
0 new messages