spawnl and waitpid
naima.mans at gmail.com
naima.mans at gmail.com
Wed Feb 28 04:13:53 EST 2007
On 27 fév, 19:31, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On 27 Feb 2007 05:39:51 -0800, naima.m... at gmail.com declaimed the
> following in comp.lang.python:
>
>
>
> > On 27 fév, 12:27, Thinker <thin... at branda.to> wrote:
> > > -----BEGIN PGP SIGNED MESSAGE-----
> <snip>
>
> > > Your program will be blocked here until child process being terminated.
> > > You should print your messages before this line.
>
> > i have tried as you said (cf bellow) and same result...
>
> No, you did NOT do as was suggested (unless you misunderstood which
> line "before this" meant.
>
> > is there any link which explain how a server Web read script and send
> > the answer ?
>
> > -------------------------------------------------------------------------
> > pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> > \python.exe","python","Main.py")
> > ret = os.waitpid(pid,0)
>
> As soon as you execute os.waitpid(), your script WAITS. NOTHING
> after that point will happen until the process you are waiting on exits.
>
> > print """please wait ...."""
> > sys.stdout.flush()
> > # retourne le process id
> > if ( ret[1] != 0):
> > print """ wait %i """ %ret[1]
> > sys.stdout.flush()
> > else:
> > print """ end %i """ %ret[1]
> > sys.stdout.flush()
>
> pid = os.spawnl(os.P_NOWAIT,
> "c:\\python25\\python.exe",
> "python",
> "Main.py") #apparently a Windows OS
> print "Please wait ..."
> sys.stdout.flush()
> ret = os.waitpid(pid, 0)
>
> if ret[1]:
> print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> else:
> print "Successful exit"
> sys.stdout.flush()
>
> {I'm presuming a 0 return code means success... VMS used 1 for success
> and 0 for failure [actually, odd numbers were informational status, even
> numbers were error status]}
>
> > ---------------------------------------------------------------------------
> > thanks
>
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfr... at ix.netcom.com wulfr... at bestiaria.com
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: web-a... at bestiaria.com)
> HTTP://www.bestiaria.com/
hello
thanks a lot..
sorry for misunderstanding, my english isn't good (i'm french).
i have tried like this:
----------------------------------------------
#! C:/Python25/python.exe
# -*- coding: cp1252 -*-
import cgitb; cgitb.enable()
import os,sys
print "Content-Type: text/html"
print
pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
print "please wait.."
sys.stdout.flush()
ret = os.waitpid(pid,0)
# retourne le process id
if ret[1]:
print "Non-zero exit code: %s %s" % (ret[1], ret[0])
else:
print "Successful exit"
sys.stdout.flush()
--------------------------------------------------------
and the result:
At the end of the script execution it write:
==>>>> please wait.. Successful exit
The browser doesn't let the script executing on background to write
the message at once.. it waits the end.
what happend?
More information about the Python-list
mailing list