python - 如何在龙卷风中使用电机?
问题描述
class Global(RequestHandler):
async def post(self):
self._auto_finish = False #关闭长链接
IOLoop.current().spawn_callback(self.do_find)
async def do_find(self):
if self.settings["admin"] != 1:
cursor = db.find(projection={'_id': 0})
documents = [document for document in (await cursor.to_list(length=100))]
print(documents)
self.write("ok")
self.finish()
tornado==6.0.4 motor==2.1 这是我根据motor官网写的代码。开启长链接时,同步查询电机编程;当长链接关闭时,电机可以异步,但不能返回任何值。响应状态码是200。请问,龙卷风和马达是怎么用的?
解决方案
spawn_callback
用于在您已经向调用者返回响应之后执行的“即发即弃”任务。这不是你想要的。您想像普通协程一样调用和等待do_find
(并且不要触摸_auto_finish
):
async def post(self):
await self.do_find()
推荐阅读
- javascript - “member.guild.username”在消息中显示为“未定义”
- kiwi-tcms - 有没有办法在测试运行中对 500 个测试用例进行排序(KIWI TCMS)
- json - 无法解析 Azure 数据工厂 ADF 中的 JSON 列表
- java - Android Sdkmanager:线程“主”java.lang.NoClassDefFoundError 中的异常:
- common-lisp - 如何在 Common Lisp 中创建函数指针数组?
- c# - 使用“TSC TTP-244 Pro”打印机打印条码
- format - gnuplot:具有恒定功率的轴上的值的格式
- mongodb - MongoDB:数据分区上的磁盘 I/O 百分比利用率已经消失
- java - 如何在scala中动态键入cast Any?
- amazon-redshift - Parquet 中 Redshift COPY 的时区问题