Integrating Twisted with existing frameworks

published Jul 04, 2006, last modified May 18, 2007

by Mr. Moshe Zadka (B-hive Networks)

Joe Developer thinks Twisted is overkill, so he tries to code his own server. But it can only serve one client at a time. But Twisted is overkill, right, so he tries some more clever ideas, with forkingTCPServer. Still doesn't work. So he finally tries out Twisted.

Twisted is:

  • high Level: for basic things you need just a few lines. It makes the common case easy.
  • with good abstractions. Try defer.Deferred() for processing values that don't exist, which is actually handy. That is a structured way for handling errors.

His Twisted program uses one thread at this point, which is not good when every line received takes long to process. To solve that you can use the process protocol. Or deferred.deferToThread()

You could use the standard python socket library. But Twisted was written because this is hard to use.