-1
我正在使用python烧瓶建立一个站点。当它混淆了我,我在这里展示我的处境不佳:在烧瓶中完成异步响应
...
@app.route('/wanted_delay_response')
def delay_response():
def background_work():
# I want to check some flags in the background
# this should not block, but it does as I try below
pass
gevent.spawn(background_work)
# the most confusing part comes:
return 'This is not what I really want to response'
如上图所示,后台工作将继续在后台运行,但结果我想应该是来自它。
但是,我不知道如何通知服务器处理其他请求,当后台工作正在运行,但有任何结果。
还是有没有优雅的搁置当前请求,并且在后台工作完成后回来响应,在间隔内,服务器可以处理其他请求吗?
谢谢你提供这样一个很好的解决方案。对于我来说,HTTP请求只是在短时间内存在,这是真的可以接受的。 Websockets模块对我来说显示出很大的优势,不仅适用于我遇到的当前情况,而且适用于合并服务器的其他部分。 – xete