Search code examples
twistedazure-web-app-servicetwisted.web

Running Twisted on Azure Websites


Can Azure Websites host Twisted applications? e.g. something like:

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

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

From http://azure.microsoft.com/en-us/documentation/articles/web-sites-python-configure/ it sounds like only WSGI apps are supported, but just wanted to confirm from an Azure Websites expert that there's no way to directly run something like the above.

--

This excerpt from discussion with Glyph (Twisted author) in the #twisted.web IRC channel covers the Twisted half of this question:

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

If there is in fact no way to directly run something like this, it seems like choosing a language other than Python buys you more flexibility on Azure Websites. For example, from http://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac/ it looks like you can host a Node app on Azure Websites which speaks HTTP directly. Confirmations or corrections gratefully received.


Solution

  • Please check https://social.msdn.microsoft.com/Forums/en-US/ed1c80c4-4621-4d02-8902-6ecc1166ac8c/running-twisted-on-azure-websites?forum=windowsazurewebsitesprevie&prof=required for answer.

    As you described in Running Twisted on Azure Websites .

    What you said is right. For node.js, you can host a Node app on Azure Websites which speaks HTTP directly. Please refer to http://blogs.msdn.com/b/hanuk/archive/2012/05/05/top-benefits-of-running-node-js-on-windows-azure.aspx

    For Python, there's no direct way run twiisted code via http.