gst-python gotcha |
2009-04-12
|
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.
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-04-12 @ 10:37
The code also should use gobject.idle_add(…), but that has the same issue.
Comment by Stefan Kost — 2009-04-14 @ 16:25