Created
December 9, 2014 20:39
-
-
Save xmcp123/8a9978eea314edc46c66 to your computer and use it in GitHub Desktop.
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
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