跑在龙卷风拦截code [英] Running blocking code in Tornado

查看:132
本文介绍了跑在龙卷风拦截code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个龙卷风的应用程序,我想用一个堵库有所建树。当它不可能改写库异步方式的情况下,什么是在龙卷风来执行它的方式吗?

I have a tornado app and I want to to use a blocking library to accomplish something. In cases where it's not possible to rewrite the library in an async manner, what's the way to execute it in tornado?

例如,我希望能够把一个 @Asynchronous 装饰上请求处理程序,在它启动一些长时间运行的功能,将刚刚返回响应一旦它完成。我不能只是把一个回调。最简单的例子当然是什么10秒不阻塞龙卷风唯一的线程睡眠的正确方法?

For example, I'd like to be able to put an @asynchronous decorator on a request handler, in it start some long running function that will just return a response once it's done. I can't just put a callback. The easiest example is of course what is the right way to sleep for 10 seconds without blocking tornado's only thread?

推荐答案

这似乎是我想要的是简单的创建一个新的线程/进程,这需要与做回呼到龙卷风的实际行动 IOLoop.instance()。add_callback

It seems like what I wanted was simply creating a new thread/process, and that the actual act of calling back to tornado needs to be done with IOLoop.instance().add_callback

更多信息,请这里

这篇关于跑在龙卷风拦截code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆