[Twisted-Python] Twisted-Python Digest, Vol 90, Issue 16
glyph at twistedmatrix.com
Tue Sep 20 12:48:33 EDT 2011
On Sep 20, 2011, at 12:42 PM, Fabian Rothfuchs wrote:
> Hi Daniel,
>> Sorry for any confusion, but I never said anything about using twisted as
>> a WSGI container for purposes of ensuring thread-safety. I was only
>> responding to your question about "how to wrap Django in twisted", and
>> running Django inside twisted's WSGI container is one way to do that.
> Oh alright - sorry :)
>> If you can afford to make the change, running twisted as a completely
>> separate service in another process, and implementing communication
>> between your Django server and your twisted server via a protocol might
>> simplify things a bit in terms of coordination.
> This is exactly the kind of architecture I'm currently spying out :)
> Thanks for confirming the general correctness of my idea!
You can't run Django by itself, though; it needs a WSGI container. So you're either dealing with coordinating between 2 pieces of software here or 3. In this case, fewer is always better :). Using Twisted's WSGI container lets you use callFromThread or blockingCallFromThread to call pretty much whatever Twisted or Twisted-using API you want; I don't see how this would be much simplified by pushing that communication over a socket, since Django isn't going to have an event loop of its own anyway, and there will be blocking communication at some point.
There's nothing wrong with coordinating with Twisted via a socket, it will work fine, but it's extra complexity that you probably don't need. I would recommend using Twisted's WSGI support and using callFromThread most cases.
More information about the Twisted-Python