本文介绍了Pynotify可以很好地交互运行,但是以编程方式运行时会崩溃(在Fedora 13上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将pynotify用于一个小型项目,但是在我的Fedora 13机器上遇到了一个奇怪的问题.似乎当以编程方式运行pynotify时,调用show()会崩溃-但是如果我自己键入该行,它将运行正常!我也在Ubuntu盒子上对其进行了测试,它在这里运行得非常好.

I am attempting to use pynotify for a small project, but am having a strange problem on my Fedora 13 machine. It appears that when pynotify is run programmatically it crashes when show() is called - however if I type that line myself it runs fine! I have tested it also on my Ubuntu box, where it runs absolutely fine.

我的测试代码是:

import pynotify

pynotify.init('someName')
n = pynotify.Notification("Summary", "Body")
n.show()

运行此命令的结果:

$ python -i test.py 
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    n.show()
glib.GError: Unable to connect to server
>>> n.show()
True
>>> 

那么,有没有人有什么想法可能导致这种行为?不幸的是Fedora环境是我无法控制的环境,因此任何需要root访问/etc的解决方案都无法真正起作用.如果需要,我可以尝试在本地安装pynotify.感谢您的帮助.

So, does anyone have any ideas what may cause this sort of behaviour? Unfortunately the Fedora environment is one that I have little control over, so any solutions requiring root access/etc would not really work. I can try installing pynotify locally, however, if needed. Thanks for any help.

推荐答案

由于Owen拒绝接受我的报价,因此这是对我有用的解决方案.请注意,我不知道为什么这行得通(除了模糊的猜测),而且我不保证这是否是一个好的解决方案,但是也许您的位置与我一样奇怪这会有所帮助吗?

Since Owen has not accepted my offer to take this answer, here is the solution that worked for me. Note that I have no idea why this works (other than vague guesses), and that I don't make any sort of guarantees about whether this is a good solution or not, but maybe if you are ever in as odd a position as I was this will help.

如果执行两次n.show(),它将第二次成功运行.因此,为了避免在Pynotify正常运行的系统上设置两个通知,我使用了以下内容:

If you execute n.show() twice, it will run successfully the second time. Therefore, in order to avoid setting two notifications on a system where Pynotify does work correctly, I have used the following:

import pynotify

pynotify.init('someName')
n = pynotify.Notification("Summary", "Body")
try:
    n.show()
except:
    n.show()

当然,请注意,这个小例子有缺陷,如果在Pynotify上存在实际问题,并且在两个n.show()上都存在实际问题,则至少是有缺陷的-这仅仅是一个最小的工作示例.

Note of course that this small example has flaws, least of all the outcome if there is an actual problem with Pynotify that will be thrown on both n.show()s - this is merely a minimum working example.

这篇关于Pynotify可以很好地交互运行,但是以编程方式运行时会崩溃(在Fedora 13上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 12:18