[Twisted-Python] Connecting to multiple servers

Gerrat Rickert grickert at coldstorage.com
Tue Jul 7 13:34:32 EDT 2009


>-----Original Message-----
>From: twisted-python-bounces at twistedmatrix.com [mailto:twisted-python-
>bounces at twistedmatrix.com] On Behalf Of Antonio Beamud Montero
>Sent: Tuesday, July 07, 2009 1:14 PM
>To: Twisted general discussion
>Subject: [Twisted-Python] Connecting to multiple servers
>
>Hi all:
>What's the smart way to close the reactor and exit in an app like that:
>

...you could try this (slightly modified from your example):

from twisted.internet import reactor, defer
from twisted.web.client import getPage

def gotPageCallback(page):
     print "got a page!"

dlist = [getPage('http://www.google.com').addCallback(gotPageCallback)]
dlist.append(getPage('http://www.yahoo.com').addCallback(gotPageCallback
))

defer.DeferredList(dlist).addCallback(lambda _: reactor.stop())

reactor.run()




More information about the Twisted-Python mailing list