简体   繁体   中英

How to Disconnect a python DBus connection?

I made some kind of answering machine for pidgin client that uses Linuxes DBus to make connection with pidgin. the code is this:

class DBus_Answer():
    def __init__(self, text = "No text"):  
        self.answer = text
        bus_loop = DBusQtMainLoop(set_as_default=True)
        self.bus = dbus.SessionBus()
        self.bus.add_signal_receiver(self.pidgin_control_func,
                                     dbus_interface="im.pidgin.purple.PurpleInterface",
                                     signal_name="ReceivedImMsg")

    def pidgin_control_func(self, account, sender, message, conversation, flags):
        obj = self.bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
        purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
        purple.PurpleConvImSend(purple.PurpleConvIm(conversation), self.answer)

now I want to use it as a module in another program. I called it like this:

answering_machine.DBus_Answer(message)

the problem is, when I stop the second program (the program that has this one as a module) and then start it again, I'll get a segmentation fault because it want to make another connection to the DBus and it seams it's not regular!

Other wise I want to give the chance of disabling this module to user. I tried to use an if statement. It will work for the first time. but if user run the module for once, he can't disable it any more.

出现分段错误是因为在python模块(用C编写)中指针为NULL,或者因为它指向随机内存(可能从未初始化为任何东西),或者因为它指向已被释放/释放/“删除”的内存。因此您的问题可能出在您的记忆上。请尝试使用此处介绍的方法跟踪segfault

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM