Skip to content

Instantly share code, notes, and snippets.

@habnabit
Forked from anonymous/gist:5bffe8b16e6f6e7a4618
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save habnabit/d1f7f8f6ccfb1c890f0e to your computer and use it in GitHub Desktop.
Save habnabit/d1f7f8f6ccfb1c890f0e to your computer and use it in GitHub Desktop.
import treq
from twisted.internet import defer, task
def testD():
def makeRequest():
d = treq.get('http://example.com/')
d.addErrback(handleError)
return d
def handleError(res):
print 'ERROR'
def handleResponse(res, count):
count += 1
print count
if count < 10:
d = makeRequest()
d.addCallback(handleResponse, count)
return d
else:
return res
return makeRequest().addCallback(handleResponse, 0)
def main(reactor):
return testD()
task.react(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment