[Twisted-Python] unblocking smtp send?

Kevin Mateo Lim k7lim at cs.stanford.edu
Thu Jul 3 12:01:15 MDT 2008


My webapp is blocking on this sendmail code that I wrote:

        from twisted.internet.ssl import ClientContextFactory
        from twisted.internet.defer import Deferred
        from twisted.mail.smtp import ESMTPSenderFactory
        from twisted.internet import reactor
        import twisted.python
        import sys
        import StringIO


        twisted.python.log.startLogging(sys.stdout)

        contextFactory = ClientContextFactory()
        result = Deferred()
        message_io = StringIO.StringIO(message_str)

        do_auth = bool(username and password)
        factory = ESMTPSenderFactory(username, password, from_addr,
to_list, message_io, result, contextFactory=contextFactory,
                       requireAuthentication=do_auth,
requireTransportSecurity=use_tls)
        reactor.connectTCP(smtp_host, smtp_port, factory)
        result.addCallback(lambda ign: reactor.stop())
        reactor.run(installSignalHandlers=0)


Is there any way I can allow the UI to continue, without blocking on
this code?  According to the logs, there was a 30second cap between
starting factory and stopping:

2008-07-03 13:24:16-0400 [-] Log opened.
2008-07-03 13:24:16-0400 [-] Starting factory
<twisted.mail.smtp.ESMTPSenderFactory instance at 0x203d3c8>
2008-07-03 13:24:49-0400 [ESMTPSender,client] Stopping factory
<twisted.mail.smtp.ESMTPSenderFactory instance at 0x203d3c8>
2008-07-03 13:24:49-0400 [-] Main loop terminated.




More information about the Twisted-Python mailing list