Spinning off time intensive procedures to speed CGI

Erno Kuusela erno-news at erno.iki.fi
Wed Dec 13 02:02:59 CET 2000


In article <916bpn$a6i$1 at nnrp1.deja.com>, leejor at my-deja.com writes:

| I want to spin off these proceedures to
| allow the original program to imediately continue.

pid = os.fork()
if pid == 0:
   # child process
   try:
        save_log_file() 
   finally:
        os._exit(0)
else:
   # parent process (pid contains process-id of child process)
   [continue execution as usual]


you can probably also do this with threads, if you need your cgi
program to work on windows and unix. (though then you are excluding
platforms that don't support threads, incl. many unixes)

the trick is to close stdout when you are done with the thread that
talks to the browser, that will close the connection to the remote
ttp client. caveat emptor: i haven't tried this (recently enough
to remember, anyway).

  -- erno



More information about the Python-list mailing list