正好6次请求后,python aiohttp-sse超时

问题描述 投票:0回答:1

我正在使用aiohttp-sse在python 3.6中编写一个sse服务器。但是,每当我向服务器发出六个sse请求时,服务器会超时所有其他连接(我只是在Google Chrome上看到一个持续的“待定”)。注意,不会产生错误。这是我的代码:

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)

我在subscribe函数中添加了print语句,用于打印'new sub'。六次连接后,此print语句甚至没有运行。因此,我知道在六个sse连接之后不会调用subscribe函数。我认为这可能是aiohttp配置的问题。有没有人对此有所了解?

我注意到的另一件事是,当六个sse连接之后发生超时时,静态页面也不起作用 - 我在尝试加载时也会出现超时。

任何帮助,将不胜感激。

python python-3.x server server-sent-events aiohttp
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.