tornodo asynchronous request

1. asynchronous access request

# 1 is to ensure that asynchronous request 
class the Test (tornado.web.RequestHandler): 

    DEF GET (Self): 
        self.write ({ ' K1 ' : ' V1 ' }) 

    DEF POST (Self): 
        self.write ({ ' K1 ' : ' V1 ' }) 


@ gen.coroutine 
DEF doing ():
     # the time.sleep (. 3) when synchronized with #, asynchronous ineffective 
    the yield tornado.gen.sleep (10 )
     the raise tornado.gen.Return ( ' Hello ' ) 


class  Test1 (tornado.web.RequestHandler):
    @ gen.coroutine 
    DEF get(self):
        res = yield doing()
        self.write(res)

    def post(self):
        self.write({'k2': 'v2'})
test

result:

http://127.0.0.1:8000/test1/ 10 second delay, http://127.0.0.1:8000/test/ affected, normal access.

Guess you like

Origin www.cnblogs.com/liuer-mihou/p/11424629.html