I am writing an sse server in python 3.6 with aiohttp-sse. However, whenever I make exactly six sse requests to the server, the server timesout all further connections (I just see a constant 'pending' on Google Chrome). Note, no errors are produced. Here is my code:
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)
I added the print statement in the subscribe function that prints 'new sub.' After six connections, this print statement is not even run. Thus, I know that the subscribe function is not called after six sse connections. I think this might be a problem with aiohttp config. Does anyone know anything else about this?
Another thing I noted was that when the timeouts started occurring after the six sse connections, static pages wouldn't work either — I would also get a timeout when trying to load them.
Any help would be appreciated.