pokerbirch
October 5th, 2010, 03:45 PM
I have a Python script that does some process management. All is working fine except for when it launches Firefox. We can normally launch a process as none-blocking and then terminate() it when we are finished, however with FF, the parent process terminates as expected but leaves the main FF window open. I am assuming that the parent is a launch script and the FF window is a child process? Even when my Python script exits, the FF instance remains. To reproduce this:
from subprocess import Popen
url = 'http://google.com'
cmd = ['firefox', '-no-remote', '-P', 'default', url]
proc = Popen(cmd)
sleep(10)
proc.terminate()
print 'terminated??'
It appears that our Popen launches the script at /usr/bin/firefox.sh which in turn opens the binary at /usr/lib/firefox-3.6.10/firefox-bin (on my system). I've tried launching firefox-bin directly but it throws an error and becomes a Zombie in my process list. The only successful kludge so far is to launch FF via a Popen'd xterm and then .terminate() the xterm when done. Downsides are that
a) FF thinks it has crashed and always starts up with the "restore session" error page (can be disabled in about:config but I want to avoid special settings)
b) all output goes to the xterm rather than my python instance
c) the xterm is visible
There is very likely a simple solution to all this, however my brain has gone a bit fuzzy from all the Googling and document reading.
from subprocess import Popen
url = 'http://google.com'
cmd = ['firefox', '-no-remote', '-P', 'default', url]
proc = Popen(cmd)
sleep(10)
proc.terminate()
print 'terminated??'
It appears that our Popen launches the script at /usr/bin/firefox.sh which in turn opens the binary at /usr/lib/firefox-3.6.10/firefox-bin (on my system). I've tried launching firefox-bin directly but it throws an error and becomes a Zombie in my process list. The only successful kludge so far is to launch FF via a Popen'd xterm and then .terminate() the xterm when done. Downsides are that
a) FF thinks it has crashed and always starts up with the "restore session" error page (can be disabled in about:config but I want to avoid special settings)
b) all output goes to the xterm rather than my python instance
c) the xterm is visible
There is very likely a simple solution to all this, however my brain has gone a bit fuzzy from all the Googling and document reading.