How can I suppress traceback on "IOError: Stream is closed" exceptions?

257 views
Skip to first unread message

Debby Mendez

unread,
Oct 1, 2012, 12:25:33 PM10/1/12
to python-...@googlegroups.com
Two questions:
1. If I don't care about "Stream is closed" errors after writing a response to a request, how can I get tornado to ignore them (currently I get a traceback to stdout)?
2. Is there a way to intercept all exceptions even if thrown when RequestHandler.write() is completing asynchronously?

I suppose #2 is a generalization of #1.

I tried searching this discussion and came up with some similar questions, e.g. 
but it's not clear to me what the best answer is in Python 2.4

Jon Parise

unread,
Oct 1, 2012, 2:49:35 PM10/1/12
to python-...@googlegroups.com
On Mon, Oct 1, 2012 at 9:25 AM, Debby Mendez <de...@josesmex.com> wrote:

> 1. If I don't care about "Stream is closed" errors after writing a response
> to a request, how can I get tornado to ignore them (currently I get a
> traceback to stdout)?

I just filed a new ticket[1] regarding these errors. I include my
current work-around, which is to do the following in a RequestHandler
subclass:

def finish(self, chunk=None):
if not self.request.connection.stream.closed():
super(RequestHandler, self).finish(chunk)

[1] https://github.com/facebook/tornado/issues/601

Nick Jennings

unread,
Oct 1, 2012, 5:44:06 PM10/1/12
to python-...@googlegroups.com
I've had this issue as well, you'll probably see the discussion if you
search the list. I use a patch similar to what Jon pasted I believe.

Debby Mendez

unread,
Oct 2, 2012, 9:26:34 AM10/2/12
to python-...@googlegroups.com
Jon & Nick -
Thanks you very much - that did the trick.
Any thoughts on my question #2?
Debby  
Reply all
Reply to author
Forward
0 new messages