首先,当我需要从三个不同的集合进行查询时,如何简化语法:
@gen.coroutine
def _prepare_comment_extra(self, extra):
(material, _), _ = yield gen.Task(self.db["material"].find_one,
{"_id": extra["material_id"]})
(course, _), _ = yield gen.Task(self.db["course"].find_one,
{"_id": extra["course_id"]})
(theme, _), _ = yield gen.Task(self.db["theme"].find_one,
{"_id": extra["theme_id"]})
raise gen.Return({
"material": material,
"course": course,
"theme": theme})
对我来说,这看起来非常令人畏惧。有没有办法写得更清楚些?!在
第二个问题是关于使用马达龙卷风。并发. 我发现在ThreadExecutor中使用马达操作是不可能的。它引发异常“无法切换到下一个线程”。我知道,ThreadExecutor被分配以异步方式执行阻塞任务。但是,我们可以用同样的连接方式以同步模式运行电机吗?在
最后一个问题: 如果我们在run_onu executor函数中使用add_callback会发生什么?!我们会退出ThreadExecutor吗?在
^{2}$
目前没有回答
相关问题 更多 >
编程相关推荐