Present Perfect


Picture Gallery
Present Perfect

gst-python gotcha

Filed under: GStreamer,Hacking,Python — Thomas @ 9:39 am

9:39 am

Here’s an innocent little line of code that caused me to lose an hour of debugging and svn bisecting time yesterday:

gobject.timeout_add(0L, self._pipeline.set_state, gst.STATE_PLAYING)

That change was buried inbetween some other cosmetic changes, and caused the UI of my application to be frozen. It took me a while before I nailed it down to this line, and a little bit more to figure out exactly why.

The goal was to set the state of the pipeline to PLAYING ‘as soon as possible’, from the main thread.

Of course the line of code does something subtly different. timeout_add schedules a call, so that part’s fine. But, the call gets rescheduled automatically unless the call returns False. Since that returns a GST_STATE_CHANGE enum, as long as the state change doesn’t fail, it keeps getting rescheduled, over and over. So, no time for the UI to update.

I figure this is something I”m bound to run into again, so a little blog will increase my chances of figuring it out again next time.


  1. You could probably argue that pygobject should issue a warning if timeout or idle functions return something other than None, False or True. Anything else probably indicates a bug.

    Comment by James Henstridge — 2009-4-12 @ 10:37 am

  2. The code also should use gobject.idle_add(…), but that has the same issue.

    Comment by Stefan Kost — 2009-4-14 @ 4:25 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment