Search code examples
pythonasynchronoustornado

Running blocking code in Tornado


I have a tornado app and I want to to use a blocking library to accomplish something. In cases where it's not possible to rewrite the library in an async manner, what's the way to execute it in tornado?

For example, I'd like to be able to put an @asynchronous decorator on a request handler, in it start some long running function that will just return a response once it's done. I can't just put a callback. The easiest example is of course what is the right way to sleep for 10 seconds without blocking tornado's only thread?


Solution

  • It seems like what I wanted was simply creating a new thread/process, and that the actual act of calling back to tornado needs to be done with IOLoop.instance().add_callback

    More information is available here