Python/Linux/守护进程试图显示 gtk.messagedialog
在 Ubuntu 8/9 上, 我正在尝试用 python 编写一个守护进程,它监视特定的网络状况并使用 gtk.messagedialog 通知用户。 我使用 rc-update 安装了这个脚本。 该守护进程在启动时启动,但即使在我登录后也不显示该对话框。我假设是因为 init.d 在 tty1 启动我的守护进程,并且没有可用的 gnome。 尝试通过子进程运行对话框,但它似乎继承了相同的运行环境。 这种事情的最佳实践是什么。
on Ubuntu 8/9,
i'm trying to write a daemon in python, that monitors a certain network condition and informs the user using a gtk.messagedialog.
I installed this script using rc-update.
The daemon starts at boot, but doesn't show the dialog even after I login. I assume because init.d starts my daemon at tty1 and no gnome is available.
Tried running the dialog through a subprocess, but it seems to inherit the same run environment.
Whats the best practice for this sort of thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果五个用户登录到 X 会话,谁会收到该消息?每个人?
如果某人在本地登录但仅使用 tty 而不是 X11,他们应该看到该消息吗?
如果有人通过 ssh -X 远程登录并在自己的系统上脱离您的 CPU 运行图形应用程序,他们是否应该看到该消息?你会如何把它交给他们?
Linux 对于您当前的方法来说太灵活了。执行此操作的标准方法是,任何对您发送的消息类型感兴趣的用户都可以运行一个应用程序来接收消息并以其选择的方式显示消息。 Dbus 是设置消息传递过程的一种流行方式。这样,远程用户或仅使用 TTY 模式登录的用户仍然可以选择查看消息。
If five users are logged in to X sessions, who gets the message? Everyone?
If someone is logged in locally but only using the tty, and not X11, should they see the message?
If someone is logged in remotely via ssh -X to run a graphic application on their own system off of your CPU, should they see the message? How would you get it to them?
Linux is too flexible for your current approach. The standard way to do this is for any user who is interested in the kind of message you are sending to run an application that receives the message and displays it in a way of its choosing. Dbus is a popular way of setting up the messaging process. This way remote users or users logged in with TTY mode only still have an option for seeing the message.
为了查明您的代码是否完全有效,您应该首先尝试在图形 shell(在 GNOME 桌面上)中将守护进程作为普通程序执行。
您还可以调用 zenity。
In order to find out whether your code works at all, you should first try and execute the daemon as normal program in a graphical shell (on a GNOME desktop).
You could also call zenity.
您可以使用
notify-send
(来自libnotify-bin
包)从守护程序向桌面用户发送通知。You may use
notify-send
(fromlibnotify-bin
package) to send notifications to desktop users from your daemon.