[pygtk] Unresponsive Window with commands.getstatusoutput
Stephen Kennedy
stevek at gnome.org
Thu Nov 9 05:51:08 WST 2006
> I have an app that makes a call to commands.getstatusoutput(...) and
> the system call (dd to image a drive) takes a LONG time. Obviously this
> is blocking any/all GTK calls and the window never gets refreshed so
> the user things that the app froze and then closes it.
Hi Christopher, as you know the problem is that getstatusoutput blocks
the event loop.
You have basically two options. 1) use threads 2) use nonblocking i/o.
I'm not a fan of threads for pygtk apps so I'll explain 2.
Use the subprocess module to open a pipe to the child.
Set the pipe to nonblocking (fcntl module)
Use gobject.io_add_watch to register a callback whenever there is data available
Depending on what you're reading, you may accumulate the input or
process it bit by bit.
Good luck,
Stephen.
More information about the pygtk
mailing list