joa*_*000 1 python mod-wsgi wsgi twisted twisted.web
我可以一起使用Twisted和mod_wsgi来尝试性能提升吗?
由于我没有启动reactor.listenTCP(...),我如何使用扭曲的异步方法?:
我尝试过的:
> server.wsgi
def application(environ, start_response):
status = '200 OK'
output = 'Pong!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
# How do I call a twisted async method from here?!
# like deferToThread(object.send, environ).
return [output]
resource = WSGIResource(reactor, reactor.getThreadPool(), application)
Run Code Online (Sandbox Code Playgroud)
你不能.
如果要将Twisted用作WSGI容器,请使用Twisted.如果要使用Apache,请使用Apache.但是,如果您使用Apache作为WSGI容器,那么您将无法使用Twisted中的功能,因为Twisted的事件循环与Apache进行网络I/O的方式不兼容.
你在代码示例中所做的事情是双重无意义的,就像WSGIResourceTwisted的HTTP服务器和WSGI之间的粘合剂一样; 即使你可以通过某种方式将Twisted阻塞到正在运行的Apache HTTPD进程中mod_wsgi,你也不需要a WSGIResource,因为apache会填充该角色.