[pygtk] Unresponsive Window with commands.getstatusoutput

Christopher Bland themanatuf at juno.com
Thu Nov 9 08:52:15 WST 2006


>> I've read a bunch of threads and such online but I'm having a hard time
>> wrapping my brain around this one...
>> 
>> 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.
>> 
>> I have a progress bar which I set to pulse during this operation so the
>> user gets some warm-fuzzy that it is working but that obviously doesn't
>> work.
>> 
>> Has anyone done anything similar to this and gotten the window to be
>> semi-responsive? I've been working on this for a few weeks and it's
>> killing me. Any input would be much appreciated. Thanks!

>I've used threads for all of these situations. The thread would execute
>the long running program letting the "main thread" process the event
>loop.

What I ended up doing was using the popen2.Popen4 command and kept
polling it to see if it was complete. That solved my problem.

[code]
fd = popen2.Popen4('dd if=/dev/sda of=/path/to/file.bin')
while fd.poll() == -1:
    refresDisp()

# more processing once dd is done.
[/code]

Thanks for the input! Hopefully this snippet could help others in the
future.

>> 
>> Here are some lines in from my code (I am not using threading either):
>> 
>> mygui.py
>> import moreCode
>> 
>> def progress_time out(pbobj):
>>     # increment the progress bar and do some other things
>>     return True
>> 
>> class MyGUI:
>>     def __init__(self):
>>         # all of my initialization code to get the GUI up
>>         self.timer = gobject.timeout_add(100, progress_timeout, self)
>>         self.window.show_all()
>> 
>>     def main(self):
>>         gtk.main()
>> 
>>     def startWork(self, widget, data=None):
>>         # This gets called when the user clicks a 'Start' button
>>         moreCode.doStuffNow()
>> 
>> if __name__ == '__main__':
>>     gui = MyGUI()
>>     gui.main()
>> 
>> moreCode.py
>> import commands
>> def doStuffNow:
>>     # This is where the bulk of my processing is done
>>     # including the call to image my drive.
>>     out = commands.getstatusoutput('dd if=/dev/abc
>> of=/my/path/image.bin, conv=notrunc,noerror,sync')
>>     return
>> 
>> 
>> 
>>


________________________________________________________________________
Try Juno Platinum for Free! Then, only $9.95/month!
Unlimited Internet Access with 1GB of Email Storage.
Visit http://www.juno.com/value to sign up today!




More information about the pygtk mailing list