Python DBUS SESSION_BUS - X11 依赖项
我已经在 Ubuntu 桌面上运行了示例 python 代码,效果很好:
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
from dbus.mainloop.glib import threads_init
import subprocess
from subprocess import call
gobject.threads_init()
threads_init()
dbus.mainloop.glib.DBusGMainLoop( set_as_default = True )
p = subprocess.Popen('dbus-launch --sh-syntax', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
call( "export DBUS_SESSION_BUS_ADDRESS" , shell=True )
call( "export DBUS_SESSION_BUS_PID" , shell=True )
bus = dbus.SessionBus()
# get DBUS objects, do other stuff with SESSION_BUS
# in same time we can start more independent processes with this file
# finaly kill the SESSION_BUS process
在桌面上成功后,我将代码移至仅使用 shell 的服务器版本。 dbus-launch 启动进程,但 python dbus.SessionBus() 返回错误“/bin/dbus-launch 异常终止,并出现以下错误:自动启动错误:X11 初始化失败”。
希望当进程以“dbus-launch”启动并成功运行时,SESSION_BUS 和 X11 之间不应该存在严格的依赖关系。错误出现在 python 中。
最好的解决方案是干净的 python 或 linux 环境设置,最糟糕但也许可以接受一些假的或虚拟的 X11(当我尝试时我并不幸运)
I've got running sample python code which is fine in Ubuntu desktop:
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
from dbus.mainloop.glib import threads_init
import subprocess
from subprocess import call
gobject.threads_init()
threads_init()
dbus.mainloop.glib.DBusGMainLoop( set_as_default = True )
p = subprocess.Popen('dbus-launch --sh-syntax', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
call( "export DBUS_SESSION_BUS_ADDRESS" , shell=True )
call( "export DBUS_SESSION_BUS_PID" , shell=True )
bus = dbus.SessionBus()
# get DBUS objects, do other stuff with SESSION_BUS
# in same time we can start more independent processes with this file
# finaly kill the SESSION_BUS process
After success on desktop I moved the code to the server edition which is only with shell. The dbus-launch starts the process, but python dbus.SessionBus() returns error with "/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed".
Hope there shouldn't be strict dependency between SESSION_BUS and X11 when the process started with "dbus-launch" go up and running with success. The error comes in python.
Best solution will be clean python or linux environment settings, worst but maybe acceptable with some fake or virtual X11 (I was not lucky when I try it)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在单独的 shell 中运行
export
调用。您需要捕获 dbus-launch 的输出,解析这些值,然后使用 os.environ 将它们写入环境:The problem is that you're running the
export
calls in separate shells. You need to capture the output ofdbus-launch
, parse the values, and useos.environ
to write them to the environment: