Tornado 6.1 Documentation
low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine [https://docs.python.org/3.6/library/concurrent.futures.html#module-concurrent.futures] package, allowing the result of executor.submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 931 页 | 708.03 KB | 1 年前3Tornado 6.0 Documentation
low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine [https://docs.python.org/3.6/library/concurrent.futures.html#module-concurrent.futures] package, allowing the result of executor.submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 869 页 | 692.83 KB | 1 年前3Tornado 5.1 Documentation
low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine when the next yield is reached future = self.gen.send(self.next) def callback(f): self.next = f.result() self.run() future.add_done_callback(callback) The decorator receives a Future from the generator0 码力 | 243 页 | 895.80 KB | 1 年前3Tornado 4.5 Documentation
fetch_future = http_client.fetch(url) fetch_future.add_done_callback( lambda f: my_future.set_result(f.result())) return my_future The raw Future version is more complex, but Futures are nonetheless Tornado because 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 treats it like a returned value. In Python 3.3 and later, a return response.body achieves the same result. Coroutines Coroutines are the recommended way to write asynchronous code in Tornado. Coroutines0 码力 | 333 页 | 322.34 KB | 1 年前3Tornado 4.5 Documentation
fetch_future = http_client.fetch(url) fetch_future.add_done_callback( lambda f: my_future.set_result(f.result())) return my_future The raw Future version is more complex, but Futures are nonetheless recommended Tornado because 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 treats it like a returned value. In Python 3.3 and later, a return response. body achieves the same result. 4.1.3 Coroutines Coroutines are the recommended way to write asynchronous code in Tornado. Coroutines0 码力 | 222 页 | 833.04 KB | 1 年前3Tornado 5.1 Documentation
low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine [https://docs.python.org/3.6/library/concurrent.futures.html#module-concurrent.futures] package, allowing the result of executor.submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 359 页 | 347.32 KB | 1 年前3Tornado 6.1 Documentation
low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine Decorated coroutines: – have additional integration with the concurrent.futures package, allowing the result of executor.submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 245 页 | 904.24 KB | 1 年前3Tornado 6.0 Documentation
low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine Decorated coroutines: – have additional integration with the concurrent.futures package, allowing the result of executor.submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 245 页 | 885.76 KB | 1 年前3Tornado 6.4 Documentation
low- level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine Decorated coroutines: – have additional integration with the concurrent.futures package, allowing the result of executor. submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 268 页 | 1.09 MB | 1 年前3Tornado 6.2 Documentation
low- level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine Decorated coroutines: – have additional integration with the concurrent.futures package, allowing the result of executor. submit to be yielded directly. For native coroutines, use IOLoop.run_in_executor instead0 码力 | 260 页 | 1.06 MB | 1 年前3
共 20 条
- 1
- 2