gpt4 book ai didi

python - 为什么 python gstreamer 在我的脚本顶部没有 "gobject.threads_init()"时崩溃?

转载 作者:太空狗 更新时间:2023-10-29 18:02:40 29 4
gpt4 key购买 nike

我已经编写了一个 python 脚本来使用 gstreamer(pygst 和 gst 模块)来计算重播增益标签,它因各种 gobject 错误而崩溃。我发现某个地方可以通过将以下样板放在脚本顶部来解决此问题:

import gobject
gobject.threads_init()

我试过了,成功了。谁能解释为什么这些行是必要的,为什么 pygst 自己不这样做?

最佳答案

因为,你可以在非线程环境下使用gobject。这并不罕见。在线程环境中使用gobject时,需要通过调用gobject.threads_init()显式初始化。这也将确保在调用“C”函数时释放 GIL。

同样来自函数文档:

The threads_init() function initializes the use of Python threading in the gobject module. This function is different than the gtk.gdk.threads_init() function as that function also initializes the gdk threads.

基本上,您明确告诉 gobject 模块您将使用线程并相应地对其进行初始化。

关于python - 为什么 python gstreamer 在我的脚本顶部没有 "gobject.threads_init()"时崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3782962/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com