1

我可以同时使用 Twisted 和 mod_wsgi 来尝试提高性能吗?

由于我没有启动reactor.listenTCP(...),我该如何使用twisted的异步方法?:

我试过的:

> 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)
4

1 回答 1

9

你不能。

如果你想使用 Twisted 作为你的 WSGI 容器,那么使用 Twisted。如果您想使用 Apache,请使用 Apache。但是,如果您使用 Apache 作为您的 WSGI 容器,那么您将无法使用 Twisted 的功能,因为 Twisted 的事件循环与 Apache 进行网络 I/O 的方式不兼容。

您在代码示例中所做的事情毫无意义,就像WSGIResourceTwisted 的 HTTP 服务器和 WSGI 之间的粘合剂一样;即使您可以通过 以某种方式将 Twisted 塞入正在运行的 Apache HTTPD 进程中mod_wsgi,您也不需要WSGIResource,因为 apache 将扮演该角色。

于 2012-02-18T00:04:50.000 回答