Created
August 18, 2016 20:01
-
-
Save iffy/c33efaa3c48b4a0b6a9cfc862bcab44e to your computer and use it in GitHub Desktop.
Am I not using notifyFinish right?
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
from twisted.internet import defer | |
from klein import Klein | |
class App(object): | |
app = Klein() | |
@app.route('/') | |
def index(self, request): | |
def finished(x): | |
print 'finished' | |
return x | |
request.notifyFinish().addBoth(finished) | |
return 'hey\n' | |
@app.route('/linger') | |
def linger(self, request): | |
def finished(x): | |
print 'finished' | |
return x | |
request.notifyFinish().addBoth(finished) | |
return defer.Deferred() | |
if __name__ == '__main__': | |
App().app.run('127.0.0.1', 6000) |
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
$ curl http://127.0.0.1:6000/ | |
hey | |
$ curl http://127.0.0.1:6000/linger | |
^C | |
$ curl --max-time 3 http://127.0.0.1:6000/linger | |
curl: (28) Operation timed out after 3001 milliseconds with 0 bytes received |
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
$ python finisher.py | |
2016-08-18 13:59:02-0600 [-] Log opened. | |
2016-08-18 13:59:02-0600 [-] Site starting on 6000 | |
2016-08-18 13:59:02-0600 [-] Starting factory <twisted.web.server.Site instance at 0x10a7458c0> | |
2016-08-18 13:59:03-0600 [-] "127.0.0.1" - - [18/Aug/2016:19:59:03 +0000] "GET / HTTP/1.1" 200 4 "-" "curl/7.50.0" | |
2016-08-18 13:59:03-0600 [-] finished | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment