转载时请注明出处和作者联系方式: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