[Twisted-Python] Deferred ownership and the Protocols

Andy Leszczynski leszczynscy at yahoo.com
Fri Jan 27 23:27:20 EST 2006


I am in the process of designing the custom Protocol
and will use Deferred-s in order to pass the
asynchronous results. I try to learn from the current
Twisted code base.

For instance there are two modules smtp.py and

def getPage(url, contextFactory=None, *args,
    factory = HTTPClientFactory(url, *args, **kwargs)
        reactor.connectTCP(host, port, factory)
    return factory.deferred

def sendEmail(smtphost, fromEmail, toEmail, content,
headers = None, attachments = None, multipartbody =
    d = defer.Deferred()
    factory = SMTPSenderFactory(fromEmail, toEmail, f,
    reactor.connectTCP(smtphost, 25, factory)
    return d

In the first case the deferred is owned/created by the
Factory, in the second by the sendEmail helper. Is
there any reason behind those, what is the
recommendation? If my question is not clear :-), let
me know.


More information about the Twisted-Python mailing list