python aiohttp-sse 在恰好 6 个请求后超时
python aiohttp-sse timesout after exactly 6 requests
我正在 python 3.6 中使用 aiohttp-sse 编写一个 sse 服务器。但是,每当我向服务器发出恰好六个 sse 请求时,服务器就会超时所有进一步的连接(我只在 Google Chrome 上看到常量 'pending')。请注意,不会产生任何错误。这是我的代码:
import asyncio
import json
import aiohttp
from aiohttp_sse import sse_response
from aiohttp.web import Application, Response
async def subscribe(request):
print('new sub')
async with sse_response(request) as resp:
await asyncio.sleep(1)
await resp.send('hello')
await asyncio.sleep(4)
await resp.send('hello')
await asyncio.sleep(8)
await resp.send('hello')
return resp
async def static_page(request):
return Response(text = open('static_page.html', 'r').read(), content_type = 'text/html')
# grab asyncio eventloop
loop = asyncio.get_event_loop()
# instantiate app
app = Application(loop = loop)
app.router.add_route('GET', '/sub', subscribe)
app.router.add_route('GET', '/', static_page)
# startup
aiohttp.web.run_app(app, host = '0.0.0.0', port = 8080)
我在打印'new sub.'的subscribe函数中添加了打印语句,经过6次连接,这个打印语句连运行都没有。因此,我知道在六个 sse 连接后不会调用订阅函数。我认为这可能是 aiohttp 配置的问题。还有人知道这件事吗?
我注意到的另一件事是,当超时在 6 个 sse 连接后开始发生时,静态页面也不会工作 — 我在尝试加载它们时也会超时。
如有任何帮助,我们将不胜感激。
我正在 python 3.6 中使用 aiohttp-sse 编写一个 sse 服务器。但是,每当我向服务器发出恰好六个 sse 请求时,服务器就会超时所有进一步的连接(我只在 Google Chrome 上看到常量 'pending')。请注意,不会产生任何错误。这是我的代码:
import asyncio
import json
import aiohttp
from aiohttp_sse import sse_response
from aiohttp.web import Application, Response
async def subscribe(request):
print('new sub')
async with sse_response(request) as resp:
await asyncio.sleep(1)
await resp.send('hello')
await asyncio.sleep(4)
await resp.send('hello')
await asyncio.sleep(8)
await resp.send('hello')
return resp
async def static_page(request):
return Response(text = open('static_page.html', 'r').read(), content_type = 'text/html')
# grab asyncio eventloop
loop = asyncio.get_event_loop()
# instantiate app
app = Application(loop = loop)
app.router.add_route('GET', '/sub', subscribe)
app.router.add_route('GET', '/', static_page)
# startup
aiohttp.web.run_app(app, host = '0.0.0.0', port = 8080)
我在打印'new sub.'的subscribe函数中添加了打印语句,经过6次连接,这个打印语句连运行都没有。因此,我知道在六个 sse 连接后不会调用订阅函数。我认为这可能是 aiohttp 配置的问题。还有人知道这件事吗?
我注意到的另一件事是,当超时在 6 个 sse 连接后开始发生时,静态页面也不会工作 — 我在尝试加载它们时也会超时。
如有任何帮助,我们将不胜感激。