Tornado 4.5 Documentation
log — Logging support tornado.options — Command-line parsing tornado.stack_context — Exception handling across asynchronous callbacks tornado.testing — Unit testing support for asynchronous code tornado web application The Application object Subclassing RequestHandler Handling request input Overriding RequestHandler methods Error Handling Redirection Asynchronous handlers Templates and UI Configuring HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten to be asynchronous with a callback0 码力 | 333 页 | 322.34 KB | 1 年前3Tornado 5.1 Documentation
tornado.log — Logging support tornado.options — Command-line parsing tornado.stack_context — Exception handling across asynchronous callbacks tornado.testing — Unit testing support for asynchronous code tornado web application The Application object Subclassing RequestHandler Handling request input Overriding RequestHandler methods Error Handling Redirection Asynchronous handlers Templates and UI Configuring HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine:0 码力 | 359 页 | 347.32 KB | 1 年前3Tornado 5.1 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 243 页 | 895.80 KB | 1 年前3Tornado 4.5 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten to be asynchronous with a callback Documentation Tornado Documentation, Release 4.5.3 def handle_response(response): callback(response.body) http_client.fetch(url, callback=handle_response) And again with a Future instead of a callback: from they have two major advantages. Error handling is more consistent since the Future.result method can simply raise an exception (as opposed to the ad-hoc error handling common in callback-oriented interfaces)0 码力 | 222 页 | 833.04 KB | 1 年前3Tornado 6.5 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 272 页 | 1.12 MB | 2 月前3Tornado 6.1 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 245 页 | 904.24 KB | 1 年前3Tornado 6.0 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 245 页 | 885.76 KB | 1 年前3Tornado 6.4 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 268 页 | 1.09 MB | 1 年前3Tornado 6.4 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 268 页 | 1.09 MB | 1 年前3Tornado 6.4 Documentation
httpclient import HTTPClient def synchronous_fetch(url): http_client = HTTPClient() response = http_client.fetch(url) return response.body And here is the same function rewritten asynchronously as a native coroutine: AsyncHTTPClient async def asynchronous_fetch(url): http_client = AsyncHTTPClient() response = await http_client.fetch(url) return response.body Or for compatibility with older versions of Python, using the tornado coroutine def async_fetch_gen(url): http_client = AsyncHTTPClient() response = yield http_client.fetch(url) raise gen.Return(response.body) Coroutines are a little magical, but what they do internally0 码力 | 268 页 | 1.09 MB | 1 年前3
共 20 条
- 1
- 2