Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 990
abyx Avatar asked Oct 22 '25 21:10

abyx


1 Answers

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

like image 176
abyx Avatar answered Oct 25 '25 11:10

abyx