[Twisted-Python] integrating twisted into an existing application

Itamar Shtull-Trauring twisted at itamarst.org
Tue Feb 18 10:56:14 EST 2003

On Tue, 18 Feb 2003 13:34:23 +1100
Anthony Baxter <anthony at interlink.com.au> wrote:

> Initially I was thinking I'd replace the telnet listener with a 
> twisted reactor running in it's own thread - this can then do the
> telnet server (and maybe ssh server). Moving the RADIUS or RTSP 
> listeners to twisted means I'd need to find a way to do the IMAP
> and SMTP (for message sending) in an async manner - I'm not sure
> on the best way to do this. My initial thought would be to have a
> pool of IMAP handler threads; when a RADIUS request comes in that
> needs IMAP, it grabs an IMAP thread that's free (or creates a new
> one) and gets it to do the operation (and signal back when it's 
> done). Is this sort of thing a typical way to handle a stateful
> protocol like IMAP? 

No, the typical way is to use an async protocol with Deferreds instead
of threads. Basically, anytime your blocking protocol would have a
"do something and block until we get result", you would instead of
blocking get a Deferred of the result. An example of this is in action
is the FTPClient protocol (twisted.protocols.ftp).

See http://twistedmatrix.com/documents/howto/defer

Downside is that you need to implement an IMAP client for Twisted. You
might be interested in looking at PyRAD too, btw, since it has
some sort of basic Twisted support in the latest version.

Itamar Shtull-Trauring    http://itamarst.org/
http://www.zoteca.com -- Python & Twisted consulting
***> Stop the war: http://unitedforpeace.org/ <***

More information about the Twisted-Python mailing list