import asyncio
q_transmit = asyncio.Queue()
q_receive = asyncio.Queue()
@asyncio.coroutine
def check_queue(ws):
while True:
output_msg = yield from q_transmit.get()
ws.send_str(output_msg)
@asyncio.coroutine
def websocket_handler(request):
ws = web.WebSocketResponse()
ws.start(request)
loop.call_soon(asyncio.async, check_queue(ws))
while True:
msg = yield from ws.receive()
return ws