Create a new non-blocking process using Python on Mac OS X

I found several articles and even a stack of overflow questions dedicated to this issue, but I still can't do it.

What I want to do is open a firefox instance from python. then the python application should monitor its business and ignore the firefox process.

I was able to achieve this goal on Windows-7 and XP using:

subprocess.Popen() 

On OS X, I tried:

 subprocess.Popen(['/Applications/Firefox.app/Contents/MacOS/firefox-bin']) subprocess.call(['/Applications/Firefox.app/Contents/MacOS/firefox-bin']) subprocess.call(['/Applications/Firefox.app/Contents/MacOS/firefox-bin'], shell=True) os.system('/Applications/Firefox.app/Contents/MacOS/firefox-bin') 

(and maybe some others that I forgot) is useless. The python application freezes until I close the firefox application.

What am I missing here? any clues?

+4
source share
2 answers

You need to somehow separate the process. I ripped this out of spawning process from python

 import os pid = os.fork() if 0 == pid: os.system('firefox') os._exit(0) else: os._exit(0) 

This spawns a branched headless version of the same script, which can then execute whatever you like and exit it right away.

+2
source

To show what I meant:

 import os if not os.fork(): os.system('firefox') os._exit(0) 

A version that does not exit the main Python process:

 import os if not os.fork(): os.system('firefox') os._exit(0) 
+3
source

All Articles