spawnl and waitpid

naima.mans at gmail.com naima.mans at gmail.com
Wed Feb 28 12:00:17 EST 2007


On 28 fév, 11:23, naima.m... at gmail.com wrote:
> On 27 fév, 19:32, Thinker <thin... at branda.to> wrote:
>
>
>
>
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
>
> > naima.m... at gmail.com wrote:
> > > On 27 f憝, 18:54, Thinker <thin... at branda.to> wrote:
> > > hello
> > > ha ok...
> > > i tried this one and the browser don't write the message at once...
> > > I have alos tried with thread and have the same result... :(
>
> > Does child-process terminate it-self in a very short time ?
> > It can be a race condition, here.
> > You can try to sleep for a while in child-process to make sure parent
> > being executed. Parent process may not schedule to run immediately
> > after spawn. And, you can print some thing before os.spawnl() to make
> > sure that message can be delivered successfully.
>
> > - --
> > Thinker Li - thin... at branda.to thinker... at gmail.comhttp://heaven.branda.to/~thinker/GinGin_CGI.py
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.6 (FreeBSD)
> > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> > iD8DBQFF5Hkp1LDUVnWfY8gRAtDdAKCKy8/ap5VJvZV14nhSCWYfLZdyYACffJ+Y
> > 0sHMgyaQBmsOMwq/rxEvm1Q=
> > =qjTU
> > -----END PGP SIGNATURE-----
>
> hello
>
> oki, i have test a simple script that only wait...
> when i tun the script without the server it write on 2 time which is
> normal:
> ================================================
> Content-Type: text/html
> wait
> The main program continues to run in foreground.
> [[[[(((then after 5 second ))]]]]]]]
> Fin background
> Main program waited until background was done.
> ==================================================
>
> BUT when i call it under the server web it write after 5 second all
> the message in 1 time :
> ===================================================
> wait The main program continues to run in foreground. Fin background
> Main program waited until background was done.
> ===================================================
>
> -----------------------THE SCRIPT ---------------------------
> import cgitb; cgitb.enable()
> import os,sys
> import threading, zipfile,time,Main
>
> print "Content-Type: text/html"
> print
> print "wait"
> sys.stdout.flush()
>
> class AsyncZip(threading.Thread):
>     def __init__(self, infile):
>         threading.Thread.__init__(self)
>         self.infile = infile
>     def run(self):
>         time.sleep(5.0)
>         print 'Fin background'
>
> background = AsyncZip('Main.py')
> background.start()
> print 'The main program continues to run in foreground.'
> sys.stdout.flush()
> background.join()    # Wait for background task to finish
> print 'Main program waited until background was done.'
> sys.stdout.flush()
> ---------------------------------------------------------------- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -

hello

The pb seems to be solve but no idee why as i have done lot of
changes :/  (may be the last flush or the "\n".. i'm gone
investigate..)

THANKSSSSSSSSSSSSSSSSS for helping :)

for information here the code

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

#! C:/Python25/python.exe -u
# -*- coding: cp1252 -*-
import cgitb; cgitb.enable()
import os, commands, time,Parser,config
import cgi

import sys,Function
sys.stderr = sys.stdout
print "Content-Type: text/html"
print

pid =  os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
    print "please wait...\n"
    print """Le fichier de log est consultable sur \\\\fr9033256d
\execute\%s \n""" %config.nom_log
    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()




More information about the Python-list mailing list