I have started my web server using the below statement
tornado.ioloop.IOLoop.current().start()
I have marked my methods with @gen.coroutine and return as yield In order to check if the method calls are async, i added time.sleep(5) but the method calls are all synchronous it waits for 5 sec and the executes the next statements, any other call to the tornado server just waits for the first call to complete. How to make my APIS async
I don't have any IO calls in my methods, but CPU intensive mathematical calculations.
As has been pointed out you can use tornado.gen.sleep
to get your coroutines working with sleep. However, ultimately, that's not going to help you.
Asyncronous programming is designed for the case where you want to do additional processing while there is IO to process. Routines continue to run while there is CPU work to do. So even if you use the right asynchronous primitives, you will block while running your computations.
In principle threaded programming works better in this situation, because each thread can be running at the same time making progress on CPU-bound work. However, that won't help you much with Python. Because of the way thread locking works in Python, basically only one Python thread can be running at a time. You can take a look at the multiprocessing module to see if you can run each of your computations in a separate process. That's probably the best way to make efficient use of a multi-CPU system for Python.