Tag Archives: Asynchronous

Making Requests Non-blocking in Tornado

Tornado is one of the most popular web frameworks for Python, which is based on a single thread IO loop (aka event loop). You can handle high concurrency with optimal performance. However, Tornado is single-threaded (in its common usage, although it supports multiple threads in advanced configurations), therefore any "blocking" task will block the whole server. This means that a blocking task will not allow the framework to pick the next task waiting to be processed. For example, this is the wrong way of using IOLoop: Note that get_complex_result() is called correctly, but it is blocked by time.sleep(5), which will prevent the execution of the following tasks (such as a second request to the same function). Only when the first…

Continue Reading
Contact Us
  • Tencent AI Lab, Shenzhen, China
  • cshzxie [at] gmail [dot] com