【问题标题】:Running Twisted on Azure Websites在 Azure 网站上运行 Twisted
【发布时间】:2015-02-20 01:10:44
【问题描述】:

Azure 网站可以托管 Twisted 应用程序吗?例如类似:

from twisted.internet import reactor
from twisted.web import server

site = server.Site(myresource)
reactor.listenTCP(80, site)
reactor.run()

http://azure.microsoft.com/en-us/documentation/articles/web-sites-python-configure/ 看来,似乎只支持 WSGI 应用程序,但只是想从 Azure 网站专家那里确认无法直接运行上述内容。

--

这段与 Glyph(Twisted 作者)在#twisted.web IRC 频道中讨论的摘录涵盖了这个问题的 Twisted 一半:

16:53:28 glyph: twisted has a WSGI _container_
16:53:34 glyph: twisted _is not_ a WSGI application
16:53:36 glyph: in any part
16:53:43 glyph: so you can't make twisted into a WSGI app
16:53:55 glyph: you can maybe invoke some Twisted code _from_ a WSGI app
16:54:05 glyph: but what that example is doing is speaking HTTP, and WSGI applications have to speak WSGI, they are not allowed to speak HTTP directly.
16:56:47 tos9: crochet?
16:56:56 glyph: tos9: crochet can't eat the inbound HTTP socket
16:56:58 glyph: tos9: so it doesn't help
16:57:11 glyph: you could write a thing that did the _outgoing_ traffic with Twisted, but since you can't handle the inbound request, you're bummed
16:57:37 glyph: basically Twisted's job is doing network I/O and if you're inside a WSGI stack, someone else is already doing the job of doing the network I/O

如果事实上没有办法直接运行这样的东西,似乎选择 Python 以外的语言可以为您在 Azure 网站上带来更多的灵活性。例如,从http://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/ 看来,您可以在 Azure 网站上托管一个直接使用 HTTP 的 Node 应用程序。感谢您的确认或更正。

【问题讨论】:

    标签: twisted azure-web-app-service twisted.web


    【解决方案1】:

    请查看https://social.msdn.microsoft.com/Forums/en-US/ed1c80c4-4621-4d02-8902-6ecc1166ac8c/running-twisted-on-azure-websites?forum=windowsazurewebsitesprevie&prof=required 以获得答案。

    正如你在Running Twisted on Azure Websites 中描述的那样。

    你说的对。对于 node.js,您可以在 Azure 网站上托管一个直接使用 HTTP 的 Node 应用程序。请参考http://blogs.msdn.com/b/hanuk/archive/2012/05/05/top-benefits-of-running-node-js-on-windows-azure.aspx

    对于 Python,没有直接的方式通过 http 运行 twisted 代码。

    【讨论】:

    【解决方案2】:

    是的,可以。他们的main page

    Azure 支持任何操作系统、语言、工具和框架——从 Windows 到 Linux,从 SQL Server 到 Oracle,从 C# 到 Java。

    您引用的页面显示了一个基本模板 - 它是如何设置特定 WSGI 应用程序的示例。你不必这样做。

    您可以设置虚拟机并在其上放置您喜欢的任何东西。

    【讨论】:

    • 我特意询问的是 Azure 网站,而不是 Azure 虚拟机。 Azure 网站具体不支持任何操作系统、语言、工具等。来自en.wikipedia.org/wiki/Microsoft_Azure_Web_Sites#Implementation:“Microsoft Azure 网站被实现为在运行 Windows Server 2012 和 IIS 8.0 的服务器上按需动态创建的网站。”
    • 是的,我想是的。如果您想在 Azure 上使用 Twisted,请使用 Azure 虚拟机(例如,来自 Linux 或 *BSD 映像就可以并且工作正常)。
    【解决方案3】:

    如果 Twisted 不需要安装任何特定的二进制文件(没有注册表项、硬编码路径要求等),那么您只需将相关的二进制文件复制到您的网站并调用这些位即可。

    【讨论】:

    • 谢谢,但我不确定这是否有帮助。问题是 Azure 网站是否可以托管像上面这样直接使用 http 的 Twisted 应用程序,而无需创建 WSGI 应用程序并失去异步的所有好处;或者 Azure 网站是否要求每个 Python 站点都以 WSGI 应用程序的形式实现,此时您已经错过了在 http 层处理任何事情的机会。如果我误解了您的建议,您能否提供一些示例代码来演示运行 Twisted 应用程序而无需创建 WSGI 应用程序?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多