Created
June 17, 2011 09:32
-
-
Save orestis/1031125 to your computer and use it in GitHub Desktop.
monitortest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.web.client import getPage | |
from twisted.internet import reactor, task | |
from twisted.names.client import createResolver | |
def p(s): | |
print s | |
def _getPage(address): | |
d = getPage(address, timeout=10) | |
d.addCallback(lambda _, a=address: p("OK " + a)) | |
d.addErrback(lambda e, a=address: p("NO " + a + ' ' + e.getErrorMessage())) | |
return d | |
SITES = ["apple.com", 'adobe.com'] | |
work = (_getPage('http://' + site) for site in SITES) | |
for i in range(10): | |
d = task.cooperate(work).whenDone() | |
reactor.installResolver(createResolver()) | |
reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment