【问题标题】:Using WSGI on Twisted在 Twisted 上使用 WSGI
【发布时间】:2012-02-17 21:15:45
【问题描述】:

我可以同时使用 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)

【问题讨论】:

    标签: python twisted mod-wsgi wsgi twisted.web


    【解决方案1】:

    你不能。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      相关资源
      最近更新 更多