在没有阻塞(或没有超时)的情况下在代理上调用dbus方法

时间:2010-12-10 10:56:01

标签: python dbus

我正在尝试锁定我的GNOME屏幕保护程序,但dbus .Lock方法正在等待响应。我希望等待响应(只需发送信号锁定屏幕保护程序,继续生活)。我该怎么做呢? (在实践中,这段代码是在一个线程中,所以我继续生活,但我仍然得到了令人讨厌的错误)

session_bus = dbus.SessionBus()                                                                                                                                       
screensaver_proxy = session_bus.get_object('org.gnome.ScreenSaver', '/org/gnome/ScreenSaver')                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
locked = screensaver_proxy.Lock(dbus_interface='org.gnome.ScreenSaver')
print "HELLO" # will never get called, due to:
/*
  locked = screensaver_proxy.Lock(dbus_interface='org.gnome.ScreenSaver')
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 68, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 140, in __call__
    **keywords)
  File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
    message, timeout)
  DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken
*/