os.fork() different in cgi-script?

Andreas Kuntzagk andreas.kuntzagk at mdc-berlin.de
Wed Jul 2 12:54:48 CEST 2003


Hi,

following code:

#!/usr/bin/python

import os
import sys

def main():
    print "Content-Type: text/plain\n\n"
    print os.getpid()

    childPID = os.fork()
    if childPID == 0:
        sys.exit()
    else:
        os.wait()
    
if __name__ == "__main__":
    main()

when run on a shell, gives the result:
---------------------------
Content-Type: text/plain


20953
----------------------------

but run as a cgi-script it gives:
---------------------------
21039
Content-Type: text/plain


21039
---------------------------
So it looks the main() is run 2 times. 
Is it so? And if yes, why?

I googled for this but only found a similar question from 1997 and no
answer.

Ciao, Andreas





More information about the Python-list mailing list