【发布时间】:2014-04-18 20:42:14
【问题描述】:
我有 2 个 Python 程序。我只想从一个到另一个发送一条消息(一个长字符串),我想使用 dbus。 现在,有没有简单的方法可以做到这一点?
例如,如果消息非常小,我已经部分解决了将消息放在路径中的问题。但后来我不得不使用外部程序 dbus-send:
服务器(python):
import dbus,gtk
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
def msg_handler(*args,**keywords):
try:
msg=str(keywords['path'][8:])
#...do smthg with msg
print msg
except:
pass
bus.add_signal_receiver(handler_function=msg_handler, dbus_interface='my.app', path_keyword='path')
gtk.main()
客户端 (bash:( ):
dbus-send --session /my/app/this_is_the_message my.app.App
有没有办法用 Python 编写客户端?或者,有没有更好的方法来达到同样的效果?
【问题讨论】: