You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello.
I need to disconnect inactive connections to save resources.
The ping/pong perfectly suited, I think it's fine for this.
I installed heartbeat=60 in WebSocketResponse.
But after 60 seconds the connection is not closed and instead throws an exception: Exception in callback WebSocketResponse._pong_not_received() handle: <TimerHandle when=785637 WebSocketResponse._pong_not_received()> Traceback (most recent call last): File "/usr/local/lib/python3.6/asyncio/events.py", line 127, in _run self._callback(*self._args) File "/lib/python3.6/site-packages/aiohttp/web_ws.py", line 88, in _pong_not_received self._req.transport.close() AttributeError: 'NoneType' object has no attribute 'close'
And I also saw that autoping=True by default, and heartbeat=None through what interval in this case will ping for the connections?
from aiohttp import web
async def index(request):
ws = web.WebSocketResponse(autoping=True, heartbeat=60)
await ws.prepare(request)
request.app['websockets'].append(ws)
print('connection count: '+str(len(request.app['websockets'])))
async for msg in ws:
if msg.type == web.WSMsgType.TEXT:
if msg.data == 'close':
await ws.close()
else:
ws.send_str(msg.data + '/answer')
elif msg.type == web.WSMsgType.ERROR:
print('ws connection closed with exception %s' %
ws.exception())
request.app['websockets'].remove(ws)
print('websocket connection closed')
print('connection count: '+str(len(request.app['websockets'])))
return ws
async def on_shutdown(app):
for ws in app['websockets']:
await ws.close(code=1012, message='5000')
app = web.Application()
app['websockets'] = []
app.on_shutdown.append(on_shutdown)
app.router.add_get('/', index)
web.run_app(app, host='***.***.***.***', port=8080)
Hello.
I need to disconnect inactive connections to save resources.
The ping/pong perfectly suited, I think it's fine for this.
I installed heartbeat=60 in WebSocketResponse.
But after 60 seconds the connection is not closed and instead throws an exception:
Exception in callback WebSocketResponse._pong_not_received() handle: <TimerHandle when=785637 WebSocketResponse._pong_not_received()> Traceback (most recent call last): File "/usr/local/lib/python3.6/asyncio/events.py", line 127, in _run self._callback(*self._args) File "/lib/python3.6/site-packages/aiohttp/web_ws.py", line 88, in _pong_not_received self._req.transport.close() AttributeError: 'NoneType' object has no attribute 'close'
And I also saw that autoping=True by default, and heartbeat=None through what interval in this case will ping for the connections?
Environment:
Python 3.6.1
aiohttp 2.0.6
Ubuntu 12.04
I did something wrong, or is it a bug in the code?
The text was updated successfully, but these errors were encountered: