[Twisted-Python] Deferred ownership and the Protocols

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


Hi,

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
web/client.py:

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




def sendEmail(smtphost, fromEmail, toEmail, content,
headers = None, attachments = None, multipartbody =
"mixed"):
[
]
    d = defer.Deferred()
    factory = SMTPSenderFactory(fromEmail, toEmail, f,
d)
    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.

Thx,
Andy




More information about the Twisted-Python mailing list