[pygtk] io_add_watch problem

Thomas Schüßler vindolin at gmail.com
Fri Jul 13 05:16:29 WST 2012


I have a strange problem with gobject.io_add_watch and a cairo widget in 
a pygtk program.
I'm reading joystick data from /dev/input/js0 with gobject.io_add_watch.
When data is read, a signal with the values is emitted and a widget 
draws the position on a cairo surface (see: http://imgur.com/YujKV).
This works as expected when the window is small.
But when I resize the window to fullscreen, the position indicator 
sometimes does not return to the center when I let the joystick go.
As if the cairo drawing routine is somehow interrupting the io_add_watch.
On a raspberry pi this even happens with small windows.
To debug the problem, I've added a timeout with gobject.timeout_add() 
that runs every 5 seconds and then reads from the opened joystick device.
When this timeout occurs, the data is read and the indicator snaps back 
to the center.
So this means there was data waiting on that handle which the 
io_add_watch somehow missed.
The problem with the timeout is, when no data is waiting this timeout 
blocks the application until the stick is moved again so it's not a 
working workaround :(
I've even tried streaming the joystick data over a network socket but 
the results were the same.
When I disable the drawing operation everything works perfect and no 
data is skipped.
I'm new to GTK+ so maybe I'm missing something obvious here?


More information about the pygtk mailing list