我一直试图制作异步龙卷风处理程序,但还没有成功。
我在文档中阅读并尝试了examples。
以下是记录在案的示例:
import java.util.Set;
import javax.ws.rs.core.Application;
@javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(rest.HelloWorld.class);
resources.add(rest.Search.class);
// Here continue adding all the JAX-RS classes that you have
}
}
我替换了这部分:
# localhost:8888/test
class GenAsyncHandler(RequestHandler):
@gen.coroutine
def get(self):
http_client = AsyncHTTPClient()
response = yield http_client.fetch("http://example.com")
do_something_with_response(response)
self.render("template.html")
用这个:
response = yield http_client.fetch("http://example.com")
其中 response = yield gen.Task(self.test())
代码为:
self.test()
我还有另一个 IndexHandler 应该只打印def test(callback):
while(True):
pass
,但它不起作用,因为似乎hello async
中的无限循环阻止了AFAIK这个请求意味着它不是异步的。
有任何帮助吗?
答案 0 :(得分:0)
获取一个函数(和可选的附加参数)并运行它 那些参数加上一个回调关键字参数。
http://tornado.readthedocs.org/en/latest/gen.html#tornado.gen.Task