473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1534
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick L. Nolan | last post by:
We have an application that works on Linux. It has to be ported to Windows XP, and there's one bug that's driving me crazy. There's a number-crunching program written in C++. It is invoked by a...
1
by: Rasmusson, Lars | last post by:
Hi, I have a problem doing I/O in a python thread. I want a thread to execute a command using os.popen, read its input until the end, and then print 'DONE' and terminate. However, the...
1
by: Vivien Mallet | last post by:
Hello, I use popen2.Popen4 and I experienced problems with it. Let me show you with an example. The following script is called "lines" (it prints lines of 'X'): ---------------------...
9
by: Roger Down | last post by:
Lets say I have a method UpdateCache() called from a single thread. I also have a method GetCache() called from multiple threads. When UpdateCache() is called, the cache updating is being...
0
by: Chris Chilvers | last post by:
I've found the docs to be rather scant on exactly what the second parameter to WaitHandle.WaitOne(Int32, Boolean) was for. The one named exitContext so I started playing with the synchronize...
12
by: Perecli Manole | last post by:
I am having some strange thread synchronization problems that require me to better understand the intricacies of Monitor.Wait/Pulse. I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock...
16
by: Thirsty Traveler | last post by:
I would like to create a test harness that simulates multiple concurrent users executing an individual thread. I would like this to be determined at runtime when the user specifies the number of...
22
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened...
1
by: MessyHeart | last post by:
The documentation on MSDN for the overloaded Monitor.wait(object,timespan, bool) is: public static bool Wait( Object obj, TimeSpan timeout, bool exitContext ) Releases the lock...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.