Skip to content

Instantly share code, notes, and snippets.

@iffy
Created August 18, 2016 20: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 iffy/c33efaa3c48b4a0b6a9cfc862bcab44e to your computer and use it in GitHub Desktop.
Save iffy/c33efaa3c48b4a0b6a9cfc862bcab44e to your computer and use it in GitHub Desktop.
Am I not using notifyFinish right?
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)
$ 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
$ 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