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

来源:互联网 发布:物流app源码 编辑:程序博客网 时间:2024/06/01 08:00

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

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

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

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

测试代码:

import dbusimport tracebackimport threadingdef 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 Falseif __name__ == '__main__':        for i in range(1,10000):                threading.Thread( target = test_function, args = (i, ) ).start()


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

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

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

原创粉丝点击