[Twisted-Python] Twisted-Python Digest, Vol 90, Issue 16

Fabian Rothfuchs fabian.rothfuchs at googlemail.com
Tue Sep 20 13:12:44 EDT 2011

>>>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!
>> Fabian
>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.

Well. Initially the idea was to have Django as the Application's Core, and
Twisted (e.g. The Reactor) running somewhere in the background, to be used
whenever it's needed.
For instance, if the Application needs to communicate via Telnet, Django
would tell the Reactor to do stuff.
But this now turned out to be inefficient and far too complex, if you want
to go the asynchronous way instead of the WSGI one.

The idea now is to change responsibilities.
The Application Core will be built using Twisted instead of Django, and
Django will be used as the side framework for ORM, GUI and that stuff.
Django itself can run in a separate Thread or a separate process or even
on a separate machine (which is requirement anyway).
And yes, for this the architecture, the Core needs to listen on an
event-socket that tells it stuff like 'communicate via Telnet'.
In Django, I'd realize that via Web Services - the Twisted way would be a
Socket (e.g. A Protocol), I guess.

I feel quite happy with that solution till now (planning since 4 hours and
it seems like it could be really working).


More information about the Twisted-Python mailing list