Search code examples
pythonprofilingtornado

How do I detect long blocking functions in Tornado application


I have a Tornado application and sometimes somebody adds a code that blocks for an inappropriate time.

How do I detect such functions, maybe even log which handler/coroutine method blocks for a time longer than, say, 50ms?

I'm looking at _make_coroutine_wrapper() in tornado.gen, and don't see a way to cut in, except for modifying the source - which is ok for a one-time debugging, but is there a better way?


Solution

  • You can use the IOLoop.set_blocking_log_threshold method. set_blocking_log_threshold(0.050) will print a stack trace any time the IOLoop is blocked for longer than 50ms.