Skip to content

Instantly share code, notes, and snippets.

@orestis
Created June 17, 2011 09:32
Show Gist options
  • Save orestis/1031125 to your computer and use it in GitHub Desktop.
Save orestis/1031125 to your computer and use it in GitHub Desktop.
monitortest.py
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