wait() on Popen4 object from thread?

G

Grant Edwards

I'm having problems calling the Popen4 object wait() method
from a thread. The folloing program produces an error on some
machines (but seems to work on others)

------------------------------8<------------------------------
import time
import threading
import popen2

def monitorThread():
while True:
s = p.fromchild.readline()
if s:
print s
else:
print p.wait()
watching = False
break

watching = True
p = popen2.Popen4('mplayer -quiet -slave test.avi')
threading.Thread(target=monitorThread).start()

while watching:
time.sleep(0.1)

------------------------------8<------------------------------

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap
self.run()
File "/usr/lib/python2.4/threading.py", line 422, in run
self.__target(*self.__args, **self.__kwargs)
File "testit.py", line 11, in monitorThread
print p.wait()
File "/usr/lib/python2.4/popen2.py", line 94, in wait
pid, sts = os.waitpid(self.pid, 0)
OSError: [Errno 10] No child processes


Is it a requirement that the Popen4 object's wait method be
called from the same thread that created it?

Why does it work on one machine:

Python 2.4.2 (#1, May 7 2006, 17:58:05)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

But not on another:

Python 2.4.2 (#1, May 7 2006, 17:34:02)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 
G

Grant Edwards

You do realize that this is a LOCAL definition, and is NOT the same
"watching" your later loop is waiting on...

Oops, forgot the global declaration.

However, the presence/absence of the global affect whether the
OSError happens or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top