我在MS Windows和momoko上使用最新的Tornado(4.0.2)。 当我同时运行多个请求时,我希望每个请求的执行时间不超过10秒,但事实并非如此。 这段代码出了什么问题?
import tornado.ioloop
from tornado.web import RequestHandler, Application, url
from tornado.gen import coroutine
import tornado.httpserver
import momoko
class BaseHandler(RequestHandler):
@property
def db(self):
return self.application.db
class HelloHandler(BaseHandler):
@coroutine
def get(self):
try:
cursor = yield momoko.Op(self.db.execute, 'SELECT pg_sleep(%s);', (10,))
self.write('Query results: %s<br>\n' % cursor.fetchall())
except Exception as error:
self.write(str(error))
self.finish()
def make_app():
return Application([
url(r"/", HelloHandler)
])
if __name__ == '__main__':
app = make_app()
app.db = momoko.Pool(
dsn='dbname=sandbox user=postgres password=postgres '
'host=localhost port=5432', size=4)
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(8888, 'localhost')
tornado.ioloop.IOLoop.instance().start()
为什么要等到第一个请求结束?