Skip to content

Instantly share code, notes, and snippets.

@xmcp123
Created December 9, 2014 20:39
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 xmcp123/8a9978eea314edc46c66 to your computer and use it in GitHub Desktop.
Save xmcp123/8a9978eea314edc46c66 to your computer and use it in GitHub Desktop.
import sys
import time
from twisted.internet import reactor,defer, threads
from klein import Klein
app = Klein()
num=0
reactor.suggestThreadPoolSize(30)
@app.route('/sleep_test',methods = ['GET'])
def sleep_test(request):
global num
num=num+1
ret=threads.deferToThread(sleep_me,90,num)
ret.addCallback(my_callback)
return ret
def my_callback(r):
return r
def sleep_me(secs,my_num):
for a in range(0, secs):
print "Sleeping ",my_num,"\t",a
time.sleep(1)
return("eggs"+str(my_num))
if __name__ == '__main__':
app.run('localhost',9999)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment