tornado debug mode

2,324 views
Skip to first unread message

jechu

unread,
Dec 19, 2010, 4:55:41 PM12/19/10
to Tornado Web Server
Hey all,

Whenever I get an exception in tornado, this is all it prints:

ERROR:root:Uncaught exception GET /search/hi (127.0.0.1)
HTTPRequest(protocol='http', host='localhost:8888', method='GET',
uri='/search/hi', version='HTTP/1.1', remote_ip='127.0.0.1', body='',
headers={'Host': 'localhost:8888', 'Accept-Language': 'en-
us,en;q=0.5', 'Accept-Encoding': 'gzip,deflate', 'Keep-Alive': '115',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:
1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Connection':
'keep-alive', 'Cookie': '_xsrf=9d277075731f4f71ac55e5f4c2107988',
'Cache-Control': 'max-age=0', 'If-None-Match':
'"c22b5f9178342609428d6f51b2c5af4c0bde6a42"'})
None
ERROR:root:500 GET /search/hi (127.0.0.1) 2.20ms


Is there a way to enable some debugging mode so that errors and
exceptions are printed to the console?

Thanks,

jechu

Evan Long

unread,
Dec 19, 2010, 5:14:28 PM12/19/10
to Tornado Web Server
Just specify it in your settings when you create the application
object.

app_settings = {
debug: "True"
}
tornado.web.Application([ list of handlers here], **app_settings)

jechu

unread,
Dec 19, 2010, 7:41:08 PM12/19/10
to Tornado Web Server
Thanks Evan,

So debug: "True" seems to be for template reloading, but doesn't
affect the way exceptions are printed to the console. Is there a way
to get more debugging output from the console?

gearheart

unread,
Dec 20, 2010, 4:13:57 AM12/20/10
to Tornado Web Server
Yes, I second that. Also, is there any way to set up emailing error
reports?

Didip Kerabat

unread,
Dec 20, 2010, 1:11:46 PM12/20/10
to python-...@googlegroups.com
I don't think there's anything like that in Tornado.

But you could, inside your Application instance, create SMTP instance. And then extend this method:

def send_error(self, status_code=500, **kwargs)

to email you the error message before rendering error.

- Didip -

Jeremy Kelley

unread,
Dec 20, 2010, 1:34:22 PM12/20/10
to python-...@googlegroups.com
On Sun, Dec 19, 2010 at 3:55 PM, jechu <jchonp...@gmail.com> wrote:
> Hey all,
>
> Whenever I get an exception in tornado, this is all it prints:
>
[... snip ...]

>
> Is there a way to enable some debugging mode so that errors and
> exceptions are printed to the console?

In your RequestHandler, you can override
_handle_request_exception(...) and do all kinds of things with that
exception.

We actually check if debug is enabled and if so drop into a pdb
session at that point. Makes for a very nice environment in tracking
down bugs.

-j


--
The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried – G. K. Chesterton

Ben Darnell

unread,
Dec 20, 2010, 2:01:25 PM12/20/10
to python-...@googlegroups.com
The "None" in between the two log lines in your original example is
tornado trying to print a stack trace for the exception, but the
information seems to have gotten lost somewhere. I'm not sure what
happened and can't seem to reproduce it, but if you override
_handle_request_exception to print a traceback with the traceback
module that should pinpoint the problem. Are you using tornado 1.1 or
did you pull the latest code from github?

-Ben

jechu

unread,
Dec 20, 2010, 2:10:20 PM12/20/10
to Tornado Web Server
I'm using the latest code from github. I'll try the overriding the
_handle_request_exception and see if I pinpoint it.

Thanks,

-Jon

On Dec 20, 2:01 pm, Ben Darnell <b...@bendarnell.com> wrote:
> The "None" in between the two log lines in your original example is
> tornado trying to print a stack trace for the exception, but the
> information seems to have gotten lost somewhere.  I'm not sure what
> happened and can't seem to reproduce it, but if you override
> _handle_request_exception to print a traceback with the traceback
> module that should pinpoint the problem.  Are you using tornado 1.1 or
> did you pull the latest code from github?
>
> -Ben
>
Message has been deleted

jechu

unread,
Dec 24, 2010, 11:05:04 PM12/24/10
to Tornado Web Server
So I'm not sure why the exception gets lost in the version of tornado
from github.

I installed an older tornado version from the tar file and error
displays appear to work as normal now, so I think there's a bug in the
github version.

Tay Ray Chuan

unread,
Dec 25, 2010, 3:33:58 AM12/25/10
to python-...@googlegroups.com
Try overriding _stack_context_handle_exception() to return
non-True/nothing - that gives the usual traceback on the console.

--
Cheers,
Ray Chuan

Peter Parente

unread,
Dec 25, 2010, 10:53:32 AM12/25/10
to python-...@googlegroups.com
> So I'm not sure why the exception gets lost in the version of tornado
> from github.

Agreed. I started noticing this change in behavior recently in the
github version too. I swear a few weeks ago all exceptions printed. I
think it's the result of some recent change.

--
Pete

Tay Ray Chuan

unread,
Dec 25, 2010, 11:08:51 AM12/25/10
to python-...@googlegroups.com
On Sat, Dec 25, 2010 at 11:53 PM, Peter Parente <par...@gmail.com> wrote:
>> So I'm not sure why the exception gets lost in the version of tornado
>> from github.
>
> Agreed. I started noticing this change in behavior recently in the
> github version too. I swear a few weeks ago all exceptions printed. I
> think it's the result of some recent change.

I'm pretty sure it's due to this commit:

6e7c8b9 (Avoid use of the @contextlib.contextmanager decorator., Fri Dec 10)

Going to 6e7c8b9^ gives the usual traceback.

Another way to get the traceback with tornado's master would be to
override _stack_context_handle_exception() to return non-True/nothing
(I've been trying to post this here but it's not appearing).

--
Cheers,
Ray Chuan

jechu

unread,
Dec 26, 2010, 1:44:12 AM12/26/10
to Tornado Web Server
I've figured out the issue and opened a bug report as well as
submitted a pull request in tornado. The commit/bug report can be
found here:
https://github.com/facebook/tornado/issues#issue/199

On Dec 25, 11:08 am, Tay Ray Chuan <rcta...@gmail.com> wrote:

Ben Darnell

unread,
Dec 27, 2010, 9:34:57 PM12/27/10
to python-...@googlegroups.com
OK, I've checked in a fix for this (different from the one in the #199
pull request, since that change loses the StackContext tracking).

-Ben

Taba Tabaa

unread,
Aug 3, 2013, 3:06:36 PM8/3/13
to python-...@googlegroups.com, b...@bendarnell.com
Hi,

No Debug Toolbar for Tornado?
Reply all
Reply to author
Forward
0 new messages