Skip to content

Instantly share code, notes, and snippets.

Created May 25, 2014 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5bffe8b16e6f6e7a4618 to your computer and use it in GitHub Desktop.
Save anonymous/5bffe8b16e6f6e7a4618 to your computer and use it in GitHub Desktop.
from twisted.internet import defer, reactor
import treq
count = 0
def TestD():
def handleError( res ):
print 'ERROR'
def handleResponse( res ):
global count
count = count + 1
print count
if count < 10:
d = TestD()
d.addCallback( handleResponse )
else:
return res
d = treq.get('http://0.0.0.0:8081')
d.addCallback( handleResponse )
d.addErrback( handleError )
return d
def finish():
print 'FINISH'
reactor.stop()
if __name__=='__main__':
d = TestD()
d.addCallback(finish)
d.addErrback(finish)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment