神秘的 GObject 警告:断言“G_IS_OBJECT(对象)”失败的
当我运行 GTK(Python GObject 自省)应用程序时,我收到警告,但无法找出其来源。当应用程序正在加载并且我正在填充 GtkListStore 时,在我第一次追加行后,我收到以下警告:
/usr/lib/python2.7/site-packages/gi/types.py:44: Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
return info.invoke(*args)
其余行追加后没有任何进一步的警告。事实上,它总是只引发一次,总是在第一个要附加的项目上。但是,该行的实际内容似乎并不重要;无论如何它都会发出警告。当程序完成加载时,当我在 TreeView 中浏览所有行时,它们似乎都正常。
我的列表存储看起来像这样:
self.list_store = Gtk.ListStore(bool, str, str, str, str, str, str,
str, str, str, str, GdkPixbuf.Pixbuf,
str, str, str, object, Pango.Weight)
最后几列从关联的 GtkTreeView 中隐藏,但警告发生在创建 TreeView 之前,所以我确定它来自 ListStore。不用说,我确定所有我传递的行格式正确,因为正如我所说,警告总是在第一行之后引发,无论我先添加哪一行。
有谁知道这可能是什么原因造成的?它不会阻止我的应用程序运行,所以这不是紧急情况,但我不想让它向最终用户发出警告。
编辑: 我使用 Python 的 -W all
命令行参数确认,实际上所有行都会发出警告。
我尝试使用 pdb
单步执行 append()
方法,但有趣的是,当它尝试设置时,它陷入了 gi
代码中的循环中包含 GdkPixbuf 的列的值,所以我在调试程序时从未真正看到引发的警告。我的猜测是 Pixbuf 导致了问题,但我不知道如何更改它以消除警告。 Pixbuf 在 TreeView 中正确渲染,所以我不确定发生了什么。
I have a warning when I run my GTK (Python GObject introspection) application and I can't figure out its source. When the application is loading and I'm populating a GtkListStore, after the very first time I append a row, I get the following warning:
/usr/lib/python2.7/site-packages/gi/types.py:44: Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
return info.invoke(*args)
The rest of the rows append without any further warnings. In fact, it's always only raised once, always on the first item to be appended. But, the actual contents of the row don't seem to matter; it raise the warning no matter what. When the program finishes loading, all of the rows seem to be ok when I browse them in the TreeView.
My list store looks like this:
self.list_store = Gtk.ListStore(bool, str, str, str, str, str, str,
str, str, str, str, GdkPixbuf.Pixbuf,
str, str, str, object, Pango.Weight)
The last few columns are hidden from the associated GtkTreeView, but the warning occurs before the TreeView is created, so I'm sure it's coming from the ListStore.Needless to say, I'm sure that all the rows I'm passing are in the correct format since, like I said, the warning is always raised after the first row, no matter which row I add first.
Does anyone have any idea what could be causing this? It's not preventing my application from running, so it's not an emergency, but I'd rather not have it spitting out warnings for the end user.
Edit:
I confirmed using Python's -W all
commandline argument that the warning is actually being raised for all rows.
I tried stepping into the append()
method using pdb
but, interstingly, it gets stuck in a loop in the gi
code when it tries setting the value of the column containing the GdkPixbuf, so I never actually see the warning raised when debugging the program. My guess is that the Pixbuf is causing the problem, but I have no idea how to change it to get rid of the warning. The Pixbuf renders correctly in the TreeView, so I'm not sure what is going on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对此进行疯狂的猜测...
PyGTK 似乎非常擅长制造奇怪的错误 - 尤其是那些让我们徒劳无功的错误。我已经遇到了六七个不同的此类错误,这些错误最终只是掩盖了另一个问题……有时甚至是一个不相关的问题。
尽管如此,运行谷歌搜索显示这已经被记录下来,尽管可能还没有解决......? (一个这样的例子:https://bugs.launchpad.net/ubuntu/ +source/jockey/+bug/814991)
如果这没有引发任何错误,也许您应该编写一个 catch 语句来消除最终程序中的错误?
Taking a wild guess at this...
PyGTK seems to be rather talented at creating weird errors - especially ones that send us on wild goose chases. I've fought six or seven different such errors that, in the end, are just masking another issue...sometimes even an unrelated one.
All the same, running a Google search shows that this has been documented, though perhaps not solved...? (One such example: https://bugs.launchpad.net/ubuntu/+source/jockey/+bug/814991)
If this isn't throwing any errors, perhaps you should write a catch statement in to silence the error in the final program?
问题出在 Gtk.py 的
TreeModel._convert_value
中。它检查是否可以将值放入GObject.Value()
中,但在检查值是否合适之前,它会使用类型初始化 Value。我能够通过将传递给
gtk.TreeStore()
的类型从Gdk.Pixbuf
更改为gobject.TYPE_pyOBJECT
来解决该问题。The problem is in Gtk.py's
TreeModel._convert_value
. It checks to see whether it can put the value in aGObject.Value()
, but it initialises the Value with the type before checking whether it's suitable.I was able to work around the problem by changing the type passed to
gtk.TreeStore()
fromGdk.Pixbuf
togobject.TYPE_PYOBJECT
.在许多情况下,这意味着另一个线程尝试访问 UI 线程组件。
In many cases, this means another thread attempted to access UI thread components.