ws_utilization.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:monetta 作者: hgn 项目源码 文件源码
def handle(request):
    peername = request.transport.get_extra_info('peername')
    host = port = "unknown"
    if peername is not None:
        host, port = peername[0:2]
    log.debug("web resource socket request from {}[{}]".format(host, port))

    ws = web.WebSocketResponse()
    await ws.prepare(request)

    jh = ResourceHandler(ws)
    async for msg in ws:
        if msg.type == aiohttp.WSMsgType.TEXT:
            if msg.data == 'close':
                await ws.close()
                await jh.shutdown()
                return ws
            elif msg.data == 'start-cpu-utilization':
                jh.sync_cpu_usage()
            elif msg.data == 'start-process-utilization':
                jh.sync_process_utilization()
            elif msg.data == 'get-meminfo':
                jh.get_meminfo()
            else:
                log.debug("unknown websocket command: {}".format(msg.data))
        elif msg.type == aiohttp.WSMsgType.ERROR:
            print('ws connection closed with exception %s' % ws.exception())
    return ws
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号