[2.4.2/Linux] Getting Python to fork?
Jon Ribbens
jon+usenet at unequivocal.co.uk
Mon Feb 4 09:29:53 EST 2008
On 2008-02-04, Gilles Ganault <nospam at nospam.com> wrote:
> I need to launch a Python script, and fork it so that the calling
> script can resume with the next step will the Python script keeps
> running.
>
> I tried those two, but they don't work, as the calling script is stuck
> until the Python script ends:
This should work I believe:
if os.fork():
os._exit(0)
os.setsid()
os.chdir("/")
fd = os.open("/dev/null", os.O_RDWR)
os.dup2(fd, 0)
os.dup2(fd, 1)
os.dup2(fd, 2)
if fd > 2:
os.close(fd)
# do stuff
Although bear in mind it's pretty UNIX-y.
More information about the Python-list
mailing list