apache cgi spawn P_NOWAIT?

Harry George hgg9140 at cola2.ca.boeing.com
Tue Aug 20 17:53:19 CEST 2002


I have a cgi which collects user input and then kicks off a long
(several minutes) application.  I want to exit the cgi early and let
the app continue.  Can't get it to work.  Any ideas?

[Using Apache, python 2.2, on Redhat 7.2.]

1. The obvious treatment is:
xyz.cgi:
  os.spawnv(os.P_NOWAIT,progname,[progname,arg1,arg2])

But this does not release the cgi until the spawned app is completed.


2. I've tried inserting the function from "demonize.py" in my spawned
app, and then calling with spawn.  Does not release.


3. I've tried doing double forks with cleaned environments, per notes
found on the web.  Does not release.

xyz.cgi:
    if (not os.fork()):
        #---pid==0, thus we are the child---
        #---make a clean process---
        os.setsid()
        os.umask(000)
        sys.stdin.close()
        sys.stdout = NullDevice()
        sys.stderr = NullDevice()
        if (not os.fork()):
            #---child of clean process---
            os.spawnv(os.P_NOWAIT,progname,[progname])
        else:
            #---clean process; don't need it---
            os._exit(0)
    else:
        #---original parent process---
        pass


-- 
harry.g.george at boeing.com
6-6M31 Knowledge Management



More information about the Python-list mailing list