开发者

Python GUI does not Close Child Process

My work asked me to port our program (that someone else wrote) from Windows to Linux. I have been able to successfully run the Python script and the executable program that the Python script calls in Linux.

The Python script creates a GUI, and the script uses the following command to close the GUI when the user is done:

window.connect("destroy", self.close_application)

This is in the def __init__(self): portion of the script. The GUI is created it calls the executable as a process as follows:

MY_EXE = 'My_Program'
EXE_ARGS = "-d -l"
sh = MY_EXE + ' ' + EXE_ARGS

self.proc = custom_popen.Popen('sh', std=custon_pop开发者_如何学运维en.PIPE, stdout=custom_popen.PIPE)

The problem that I am having is that the Python script never attempts to close My_Program when the user clicks the close button on the GUI. The script does properly close the GUI.

So, my question is how do I link the users selection to close the GUI to a command to close the My_Program process in the Python script?

Any help is appreciated. Also, if it is of note, the script requires pygtk 2.0.


Does the external program read from stdin and then exit? If it does, does your close_application method call self.proc.stdout.close()?

If the external program doesn't exit automatically (e.g.: when it's done reading input or doing a simple task), then you may need to kill it explicitly with Popen.close() (Python 2.6+) or os.kill().


I was able to succesfully kill the app with the os.kill() function. So, I consider this solved for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜