Python猎鹰和异步操作

编程入门 行业动态 更新时间:2024-10-28 03:21:46
本文介绍了Python猎鹰和异步操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用python3 + falcon组合编写API.

I am writing an API using python3 + falcon combination.

方法中有很多地方可以向客户端发送回复,但是由于执行DB,I/O操作等繁琐的代码,它不得不等到繁重的部分结束.

There are lot of places in methods where I can send a reply to a client but because of some heavy code which does DB, i/o operations, etc it has to wait until the heavy part ends.

例如:

class APIHandler: def on_get(self, req, resp): response = "Hello" #Some heavy code resp.body(response)

我可以在代码的第一行发送"Hello".我想要的是在后台运行沉重的代码并发送响应,而不管沉重的时间何时结束.

I could send "Hello" at the first line of code. What I want is to run the heavy code in a background and send a response regardless of when the heavy part finishes.

Falcon没有任何内置的异步功能,但是他们提到它可以与gevent之类的东西一起使用.我还没有找到有关如何将两者结合的文档.

Falcon does not have any built-in async capabilities but they mention it can be used with something like gevent. I haven't found any documentation of how to combine those two.

推荐答案

我将Celery用于异步相关的作品.我不知道gevent.请看一下 celery.readthedocs/en/latest/getting-started/introduction.html

I use Celery for async related works . I don't know about gevent .Take a look at this celery.readthedocs/en/latest/getting-started/introduction.html

更多推荐

Python猎鹰和异步操作

本文发布于:2023-10-30 02:58:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:猎鹰   操作   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!