开发者

Why does python gstreamer crash without "gobject.threads_init()" at the top of my script?

开发者 https://www.devze.com 2023-01-17 04:07 出处:网络
I have written a python script to use gstreamer (pygst and gst modules) to calculate replaygain tags, and it was crashing inconsistently with various gobject errors. I found somewhere that you could f

I have written a python script to use gstreamer (pygst and gst modules) to calculate replaygain tags, and it was crashing inconsistently with various gobject errors. I found somewhere that you could fix this by putting the following boilerplate at the top of your script:

import gobject
gobject.threads_init()

I tried it, and it worked.开发者_JS百科 Can anyone explain why these lines are necessary, and why pygst doesn't do this itself?


Because, you can use gobject in a non threading environment. This is not unusual. When you use gobject in a threading environment, you need to explicitly initialize by calling gobject.threads_init(). This will also ensure that the when "C" functions are called, the GIL is freed.

  • Python, Threads, the GIL, and C++
  • Explain Python extensions multithreading

Also from the function document :

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.

Basically, you tell gobject module explicitly that you are going to use threading and initialize it accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号