asyncore AF_UNIX socket server cpu使用率100%问题解决办法


       项目中 继承asyncore中的dispatcher 和 dispatcher_with_send 两个类实现AF_UNIX socket服务器。但是使用top命令查看该服务进程时,发现cpu使用率基本是100%。


       经过查找发现,是asyncore库存在bug(使用AF_UNIX sockets时,存在 polling loop ),需要分别修改asyncore.py文件中的 pollpoll2函数的一个if 语句。

      1.  修改poll 函数

         def poll(timeout=0.0, map=None):
             is_w = obj.writable()
             if is_r:
                 r.append(fd)
            <span style="color:#FF0000;">#if is_w:</span>
            # accepting sockets should not be writable
            <span style="color:#009900;">if is_w and not obj.accepting:</span>
                w.append(fd)
             if is_r or is_w:
                 e.append(fd)

  2.  修改poll2 函数

     def poll2(timeout=0.0, map=None):
             flags = 0
             if obj.readable():
                 flags |= select.<span style="background-color: rgb(255, 255, 255);">POLLIN</span> | select.POLLPRI
            <span style="color:#FF0000;">#if obj.writable():</span>
            # accepting sockets should not be writable
            <span style="background-color: rgb(0, 153, 0);">if obj.writable() and not obj.accepting:</span>
                 flags |= select.POLLOUT
             if flags:
                 # Only check for exceptions if object was either readable





https://hg.python.org/cpython/rev/16bc59d3786




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值