【发布时间】:2018-09-26 21:37:36
【问题描述】:
我有这么简单的代码。
from aiohttp import web
async def hello(request):
print('Start')
for el in range(30000000):
# Any expression
1+el/10000*100000-4*234
print('Stop')
return web.Response(text="Hello, world")
app = web.Application()
app.add_routes([web.get('/', hello)])
web.run_app(app)
当我在http://0.0.0.0:8080/ 中打开我的浏览器时,我看到了“开始”的文字,然后在大约 10 秒后我看到了“停止”的文字。然后我同时打开两个页面http://0.0.0.0:8080/。我希望在 10-11 秒内收到这样的短信
'Start' #right now
'Start' #right now
'Stop' #in 10 sec
'Stop' #next sec
但我得到(在 21 秒内)
'Start' #right now
'Stop' #in 10 sec
'Start' #at 11th sec
'Stop' #at 22th sec
我做错了什么?
【问题讨论】:
标签: python-3.x python-asyncio aiohttp pytest-aiohttp