[Twisted-Python] Use asyncore dispatchers with Twisted

Itamar Shtull-Trauring twisted at itamarst.org
Tue Jan 8 09:00:05 EST 2002


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()





More information about the Twisted-Python mailing list