469,890 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

wait() on Popen4 object from thread?

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.
--
Grant Edwards
gr****@visi.com

May 30 '06 #1
2 1433
On 2006-05-30, Dennis Lee Bieber <wl*****@ix.netcom.com> wrote:
On Tue, 30 May 2006 03:01:54 -0000, Grant Edwards <gr****@visi.com>
declaimed the following in comp.lang.python:
watching = False


You do realize that this is a LOCAL definition, and is NOT the same
"watching" your later loop is waiting on...
while watching:
time.sleep(0.1)


Oops, forgot the global declaration.

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

--
Grant Edwards grante Yow! Do I hear th'
at SPINNING of various
visi.com WHIRRING, ROUND, and WARM
WHIRLOMATICS?!
May 30 '06 #2
On 2006-05-30, Grant Edwards <gr****@visi.com> wrote:

doesn't
V
However, the presence/absence of the global affect whether the
OSError happens or not.


--
Grant Edwards grante Yow! I'm EMOTIONAL
at now because I have
visi.com MERCHANDISING CLOUT!!
May 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Patrick L. Nolan | last post: by
1 post views Thread by Vivien Mallet | last post: by
9 posts views Thread by Roger Down | last post: by
reply views Thread by Chris Chilvers | last post: by
12 posts views Thread by Perecli Manole | last post: by
16 posts views Thread by Thirsty Traveler | last post: by
22 posts views Thread by Jason Zheng | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.