synchronous
和Asynchronous
方法
# 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>
'''