[pygtk] Blocking main loop during execution of external program

Neil Dugan pygtk at butterflystitches.com.au
Fri May 23 09:09:46 WST 2008


Vláďa wrote:
> Hi,
> 
> I'd like to ask you for help with solving my problem. First I'll try to 
> describe what I'm doing:
> 
> I have a PyGTK application which needs to run an external command. I use 
> subprocess.Popen to do it. Then I run a gtk.Dialog (saying "Please 
> wait") and wait until the process is finished. After the external 
> process finishes I close the dialog and the program continues. So far 
> everything works fine. But now I want to change it a little. After the 
> process is finished, I want to return to the main loop but keep the 
> dialog opened. Then process results of the external program and run the 
> external program again. Repeat this a couple times and then finally 
> close the "Please wait" dialog.
> 
> I found out that I can return back while leaving the dialog opened by 
> calling dialog.return(0). But when I run the dialog again with 
> dialog.run(), Python (the interpreter) crashes. What is the problem? Is 
> it impossible to run the same dialog twice? What else could I do?
> 
> I need to block the main program loop because it can't continue before 
> the external program finishes. At the same time I want to have a pop up 
> window with a "Cancel" button (the window must be responsive). I'm 
> afraid I'm not experienced enough to use threading, which would be 
> probably best suited for this task. What would be the most simple way to 
> solve my problem?
> 
> I hope it is clear what I'm trying to do. Unfortunately my English is 
> far away from being perfect. If a code sample would help, I can post it.
> 
> Best regards,
> Vlada
Have you tried to do it with a non-blocking dialog ?
Using
	dialog.connect('response', callback)
	dialog.show()

If you want to temporaly remove the dialog use
	dialog.hide()

And when finished use
	dialog.destroy()




More information about the pygtk mailing list