dbus-python 在 thread 中运行时会随机出错

转载时请注明出处和作者联系方式:http://blog.csdn.net/mimepp

作者联系方式:YU TAO <yut616 at sohu dot com> 

关键字: linux,dbus-python, python, dbus, thread, safety

这里记录一下 dbus-python 在 thread 运行时,会有 crash 的情况。

测试代码:

import dbus
import traceback

import threading

def test_function(index):
        bus = dbus.SessionBus()
        try:
                bus_obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
                print "index: %d" % index
        except dbus.DBusException:
                print "dbus.DBusException"
                traceback.print_exc()
        return False

if __name__ == '__main__':
        for i in range(1,10000):
                threading.Thread( target = test_function, args = (i, ) ).start()


这里测试代码只用到了 get_object 方法,就会引起问题了。

PC 上是很随机的出现 bug,crash 结果如下:

index: 8898
index: 8899
index: 8900
index: 8901
index: 8902
 index: 8878
index: 8904
Segmentation fault

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值