synchronous
和Asynchronous
方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# synchronous function # You can open your browser to view the web-site. # web-site:http://www.imekaku.com/tornado/temp.html # filename: temp.py # time: 2016-9-12 19:57:51 from tornado.httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body if __name__ == '__main__': url = r"http://www.imekaku.com/tornado/temp.html" print synchronous_fetch(url) ''' output: lee@localhost:tornado-test$ python temp.py <!DOCTYPE html> <html> <head> <title>Hello</title> </head> <body> This is a html. <h2>This is for tornado test.</h2> <h3>Thx for your view.</h3> </body> </html> ''' |