История изменений
Исправление vvn_black, (текущая версия) :
def on_startup(app):
...
app['websockets'] = []
...
app = web.Application()
on_startup(app)
async def ws_handler(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].append(ws)
try:
async for msg in ws:
await ...
except Exception as e:
pass
finally:
request.app['websockets'].remove(ws)
return ws
И в другой корутине пробегаешься по списку соединений
while True:
for ws in request.app['websockets']:
await ws.send_str('ping')
await asyncio.sleep(10)
Исправление vvn_black, :
def on_startup(app):
app['websockets'] = []
...
app = web.Application()
on_startup(app)
async def ws_handler(request):
""" """
ws = web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].append(ws)
try:
async for msg in ws:
await ...
except Exception as e:
pass
finally:
request.app['websockets'].remove(ws)
return ws
И в другой корутине пробегаешься по списку соединений
while True:
for ws in request.app['websockets']:
await ws.send_str('ping')
await asyncio.sleep(10)
Исправление vvn_black, :
async def ws_handler(request):
""" """
ws = web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].append(ws)
try:
async for msg in ws:
await ...
except Exception as e:
pass
finally:
request.app['websockets'].remove(ws)
return ws
И в другой корутине пробегаешься по массиву соединений
while True:
for ws in request.app['websockets']:
await ws.send_str('ping')
await asyncio.sleep(10)
Исходная версия vvn_black, :
async def ws_handler(request):
""" """
ws = web.WebSocketResponse()
await ws.prepare(request)
request.app['websockets'].append(ws)
try:
async for msg in ws:
await ...
except Exception as e:
pass
finally:
request.app['websockets'].remove(ws)
return ws
И в другой корутине пробегаешься по массиву соединений
while True:
for ws in request.app['websockets']:
await ws.send_str('ping')
asyncio.sleep(10)