Created
March 13, 2015 14:11
-
-
Save mithrandi/8922bd4fbff4b7263d4b to your computer and use it in GitHub Desktop.
Agent timeout example
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
def fetch(..., clock=None): | |
if clock is None: | |
from twisted.internet import reactor as clock | |
def handleResponse(response): | |
# ... | |
d = agent.request(method, url, Headers(h), body) | |
call = clock.callLater(timeout, d.cancel) | |
def cancelTimeout(result): | |
if call.active(): | |
call.cancel() | |
return result | |
d.addCallback(handleResponse) | |
d.addBoth(cancelTimeout) | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment