threading+popen2 hang

lofic louis.coilliot at gmail.com
Tue Feb 2 06:30:44 EST 2010


Hello,

I've seen many messages and bug reports on popen2 about pipes, buffer
size problems, sub-processes not properly closed, race conditions,
popen2 not being thread safe... But I still can't figure what applies
to my case.

This piece of code:

#!/usr/bin/python
import threading
import popen2

class MyThread ( threading.Thread ):
   def run ( self ):
        #popenChild = popen2.Popen3("cat /etc/passwd")
        #popenChild = popen2.Popen3("/usr/bin/iostat -V")
        popenChild = popen2.Popen3("/usr/bin/iostat -k -x 1 2")
        popenChild.wait()
        print 'Bye'

MyThread().start()


Works fine on RHEL5/python 2.4.3
Hangs on RHEL4/python 2.3.4

I presume it hangs on wait().

It does not hang with:
popenChild = popen2.Popen3("/usr/bin/iostat -V") # short output
popenChild = popen2.Popen3("cat /etc/passwd") # long output

It does not hang outside of a thread:
#!/usr/bin/python
import popen2
popenChild = popen2.Popen3("/usr/bin/iostat -k -x 1 2")
#print popenChild.fromchild.readlines()
popenChild.wait()
print 'Bye'


Could someone explain this to me ?

Thanks in advance.

Louis Coilliot





More information about the Python-list mailing list