spawnl and waitpid

naima.mans at gmail.com naima.mans at gmail.com
Wed Feb 28 05:23:28 EST 2007


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()
---------------------------------------------------------------




More information about the Python-list mailing list