[Zope-Coders] Sovled: [Zope] popen hangs on W2K

Chris Withers chrisw@nipltd.com
Thu, 14 Mar 2002 20:24:31 +0000


Thomas Guettler wrote:
> 
> You could solve it with threads, too. Start two threads: one reading
> stdout, one stderr and wait
> until both have finished the read-statement.

Now, that is a brilliant suggestion...

here's the code:

> from os import getcwd, chdir, system, popen3
> 
> from threading import Thread
> 
> class NonBlockingReader(Thread):
> 
>     def __init__(self,file):
>         Thread.__init__(self)
>         self.file = file
>         
>     def run(self):
>         self.result = self.file.read()
> 
>     def read(self):
>         return self.result
>     
> dir=getcwd()
> chdir('E:\ZopeTests\sandbox\Zope3')
> (i,c,e) = popen3('c:\python22\python test.py')
> chdir(dir)
> 
> print "popened"
> ct = NonBlockingReader(c)
> print "ct created"
> et = NonBlockingReader(e)
> print "et created"
> ct.start()
> print "ct started"
> et.start()
> print "et started"
> ct.join()
> print "ct joined"
> et.join()
> print "et joined"
> 
> print ct.read()+et.read()

Thankyou very very much :-)

Now off to close a Python bug and checkin some code changes...

cheers,

Chris