Tornado源码分析-预备(1)-异步非阻塞I/O

synchronousAsynchronous方法

# 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>
'''

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部