sách gpt4 ai đã đi

Tornado @web.asynchronous @gen.coroutine VS @gen.coroutine sự khác biệt là gì

In lại 作者:行者123 更新时间:2023-12-04 23:01:29 28 4
mua khóa gpt4 Nike

hiện hữu tài liệu , 如果方法也用@gen.coroutine 修饰,则不需要@web.asynchronous。像这样

@web.asynchronous
@gen.coroutine
def get(self):
...

但是,在文档中,他们还解释说,如果您使用@web.asynchronous,那么您应该调用 self.finish()。但是,在上面的情况下(一起使用两个装饰器)连接完成而没有调用“self.finish()”

我很好奇里面发生了什么

在下面的情况下,它的工作原理与上面不同。
@web.asynchronous
def get(self):
self.test()

@gen.coroutine
def test(self):
httpClient = AsyncHttpClient()
val = yield httpClient.fetch("http://www.google.com")
print test
#self.finish()

如果未调用“self.finish()”,则连接不会关闭。

有没有人可以解释一下?

1 Câu trả lời

secret 是đây :

if isinstance(result, Future):
# If @asynchronous is used with @gen.coroutine, (but
# not @gen.engine), we can automatically finish the
# request when the future resolves. Additionally,
# the Future will swallow any exceptions so we need
# to throw them back out to the stack context to finish
# the request.
def future_complete(f):
f.result()
if not self._finished:
self.finish()
IOLoop.current().add_future(result, future_complete)
@asychronous检查返回 future 的方法(即 @gen.coroutine ),如果是,则添加 IOLoop 回调以在 future 完成时完成连接。

关于asynchronous - Tornado @web.asynchronous @gen.coroutine VS @gen.coroutine 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22967996/

28 4 0
Bài viết được đề xuất: r - Shiny 的 tabsetPanel 不在多个选项卡中显示图
Bài viết được đề xuất: r - 如何避免用data.table打印行号?
Bài viết được đề xuất: ruby-on-rails - rails 4 URI 域错误参数
Bài viết được đề xuất: scala - 如何有效地检查是否定义了两个选项?
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com