当我手动运行以下脚本时,一切正常。但是,当我通过一个 shell 脚本(以 root 身份启动脚本)通过 Upstart 启动它时,它成功地到达该wnck.screen_get_default()
行并且永远不会超过它。Upstart 一遍又一遍地重新生成脚本(因为它一直在死去)并且没有抛出异常。有任何想法吗?
import gtk
import wnck
import time
def cycle():
try:
print("ABOUT TO RUN screen_get_default!!")
screen = wnck.screen_get_default()
print("JUST RAN screen_get_default!!")
except Exception as e:
print(str(e))
print("STARTING APP!!")
while 1 == 1:
cycle()
time.sleep(1)
upstart 脚本如下所示:
description "myapp"
start on runlevel [12345]
stop on runlevel [!12345]
respawn
exec /usr/lib/myapp/myapp.sh
post-stop exec sleep 10
编辑:我exec sudo python /usr/lib/myapp/myapp.py
从新贵脚本运行,现在我终于在日志文件中得到一个有意义的错误,但我无法破译从这里去哪里:
GtkWarning: IA__gdk_x11_display_get_xdisplay: assertion 'GDK_IS_DISPLAY (display)' failed
screen = wnck.screen_get_default()
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
warnings.warn(str(e), _gtk.Warning)