"IOError: failed to write data"

4,581 views
Skip to first unread message

Pedro Ferreira

unread,
Apr 6, 2011, 9:16:40 AM4/6/11
to modwsgi
Dear all,

I recently switched from mod_python to mod_wsgi (daemon mode) in a web
app that uses a lot of AJAX calls. From then on, I started getting
many IOErrors in the log, with the message "failed to write data".
From what I understood from everything I found while googling it, this
is normal in such context.
However, my log files are spammed with all those messages, and I'd
really like to get rid of them. I thought of just ignoring the
exception, which seems to be OK as I would just wrap a try...except
around the code that calls `start_response` and catch IOError
(right?)... or are there any other situations in which there can be an
IOError that I don't want to ignore?
Any suggestions?

Thanks in advance,

Pedro Ferreira

Graham Dumpleton

unread,
Apr 6, 2011, 6:14:58 PM4/6/11
to mod...@googlegroups.com
What version of mod_wsgi are you using?

Are you returning response in good WSGI style, ie., returning
iterable, or are you using the write() callback returned by
start_response()?

Graham

> --
> You received this message because you are subscribed to the Google Groups "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
>
>

Pedro Ferreira

unread,
Apr 7, 2011, 4:15:10 AM4/7/11
to modwsgi

> What version of mod_wsgi are you using?

Version 3.3

> Are you returning response in good WSGI style, ie., returning
> iterable, or are you using the write() callback returned by
> start_response()?

I am still using the write() callback.

Cheers,

Pedro

Graham Dumpleton

unread,
Apr 7, 2011, 5:03:51 AM4/7/11
to mod...@googlegroups.com

Yep, you are seeing the messages because you are using the write()
callback and not catching the IOError and aborting the request
cleanly.

In mod_wsgi 3.X that should be the only place where it would be
evident to user code. The error can also occur when mod_wsgi consumes
a WSGI iterable, but in that case the error message will only appear
in the log files if LogLevel is debug.

Even for the latter case it used to be more noisy, but behaviour was
changed in 3.0. For details see:

http://code.google.com/p/modwsgi/issues/detail?id=29

Note that write() is not considered best practice and you should try
and return an iterable from WSGI application instead.

Graham

Reply all
Reply to author
Forward
0 new messages