[Twisted-Python] Use asyncore dispatchers with Twisted

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Jan 8 10:40:27 MST 2002


There has GOT to be a better way to do this :)

On Tue, 2002-01-08 at 08:00, Itamar Shtull-Trauring wrote:
> Yes, it is possible - you can use servers or clients written for asyncore 
> together with twisted, using the following module. Should I check it in? If 
> so, should it be in examples/ or twisted.internet, and what's a good module 
> name?
> 
> 
> ===================================================================
> """Use asyncore dispatchers with Twisted.
> 
> If you have an asyncore dispatcher, you can still use it with twisted.
> Just import this module, and don't run asyncore.loop() -- instead start
> the twisted event loop, either by calling twisted.internet.main.run(),
> or the usual way by calling an Application instance's run() method.
> """
> 
> import asyncore
> 
> from twisted.internet import main
> 
> 
> class AsyncoreLooper:
>      """Run the asyncore event loop for asyncore dispatchers."""
> 
>      def timeout(self):
>          if asyncore.socket_map:
>              return 0.0
>          else:
>              return None
> 
>      def runUntilCurrent(self):
>          asyncore.poll(0.001)
> 
> asyncoreLooper = AsyncoreLooper()
> main.addDelayed(asyncoreLooper)
> 
> if __name__ == '__main__':
>      # example, run debugging SMTP proxy (included with 2.1)
>      # telnet to port 8025 to try it out.
>      import smtpd
>      d = smtpd.DebuggingServer(("localhost", 8025), ("gateway1.att.net", 25))
>      main.run()
> 
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- 
______      you are in a maze of twisted little applications, all
|   |_\     remarkably consistent.
|     |          -- glyph lefkowitz, glyph @ twisted matrix . com
|_____|             http://www.twistedmatrix.com/





More information about the Twisted-Python mailing list