asyncoresupport.py [plain text]
"""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__':
import smtpd
d = smtpd.DebuggingServer(("localhost", 8025), ("mx1.mail.yahoo.com", 25))
main.run()