Forking problem

Chris chouster at uclink4.berkeley.edu
Fri May 31 16:42:21 EDT 2002


I'm developing a CGI script in Python. I'm forking a procedure off of
the parent and I think everything is right. The only thing that's
going wrong is that it doesnt seem to be executing the external script
in the way that I expect. I ran the external script manually from the
shell command line and it takes roughly a minute to complete, however
in the way I do it in my script (see code below) it seems to skip over
that line in a second (it would be less time but I do have a sleep
function encoded). It SEEMS as though it is skipping over the line
completely. I programmed the external script to drop a file with the
output to indicate that it has indeed done something. When I do it
manually the temp file appears, but when I do it from the program, no
temp file appears yet there are no complaints that anything has gone
wrong. I'm CONFUSED!! So please help me a) determine why it seemingly
doesnt execute my program and b) given that (a) is fixed, why no
printing occurs to my webpage even though I program my CGI script such
that it prints the processes output stream to my webpage. Thanks!

----CODE-----
if (os.fork() == 0):
		
		#(inStream, outStream, errStream) = os.popen3("sync2rnaidb_copy.py")
		#print err
		os.system("myCommand") #have faith that myCommand is correct
		print "If I see this it should mean that the process was run."
		os._exit(0)

	else:
		# controlling parent process
		while 1:
			# check if child has exited, but don't block
			(pid, status) = os.waitpid(-1, os.WNOHANG)
			if pid > 0:
				print ExHtml.startHtml("Doing request..."), \
				      "Process completed!", \
				      Html.linebreak(), \
				      Html.endHtml()
				break
			else:
				print Html.startHtml("Doing request..."), \
				      ".", \
				      Html.endHtml()

				time.sleep(1)
         #FINISH
-------------------------

---- WEB PAGE OUTPUT ----

Please wait while we process your request. . . . . 
If I see this it should mean that the process was run. 
Process completed! 



--------------------------

Everything runs smoothly (i.e. no uncaught exceptions, strack traces,
etc). I'm running off oa UNIX system if that means anything. Python
2.2.1. HELP ME PLEASE!

Chris



More information about the Python-list mailing list