-
-
Save habnabit/d1f7f8f6ccfb1c890f0e to your computer and use it in GitHub Desktop.
This file contains 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
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