New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Popen4 wait() fails sporadically with threads #41862
Comments
Calling wait() on a popen2.Popen4 object fails Traceback (most recent call last):
...
File "/usr/local/lib/python2.3/popen2.py", line 90, in wait
pid, sts = os.waitpid(self.pid, 0)
OSError: [Errno 10] No child processes when using threads. The problem seems to be a race condition when a thread The constructor of Popen4. calls _cleanup() which calls Code to replicate this behavoir is attached in popen_bug. Solution: Popen4 and Popen3 should be threadsafe. Related modules: A seemingly related error occurs with Tested on Linux RedHat Enterprise 3 for Python 2.3.3, |
Logged In: YES The attached patch fixes the problem for me. It also |
Logged In: YES I don't understand why you are setting self.sts to 0 if wait I think the whole issue can be avoid if we use resurrection: If then a thread calls poll explicitly, and another calls With that approach, I don't think further thread |
Logged In: YES I agree with your comment about setting self.sts to 0. That Although I dislike __del__, this does seem like an Note that currently all os.error's are swallowed in poll(). I wasn't really sure what to do about threads. The threads I've attached a patch which I think implements your |
Logged In: YES This looks all fine. As a further issue, I think _cleanup should also clean Putting these all together, I propose v3 of the patch. Another aspect that puzzles me is the repeated test that |
Logged In: YES It makes sense to remove from _active on ECHILD. I wondered the same thing about waitpid(), but left it as it This patch is fine with me, feel free to check it in. BTW, |
Logged In: YES Committed as 43286. I also added .cmd to Popen4. |
Logged In: YES see patch bpo-1467770 for subprocess.py library module |
Did this get fixed in subprocess.py? The patches all seem to be for popen2. I have been observing similar problems in subprocess.py, so I downloaded the test script and ran it with the -s option. It didn't work out of the box, I had to pass "shell=True" to the subprocess.Popen before it did anything at all. Which also made me wonder if the subprocess variant of this problem got forgotten. Having done that, I have observed failures using Python 2.4.4 on Red Hat EL3 Linux, and also using Python 2.4.3 on Red Hat EL4 linux. Most of the time it works, sometimes it hangs forever, and sometimes we get something that look like this: Started 20 threads
Exception in thread Thread-19:
Traceback (most recent call last):
File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap
self.run()
File "popen_bug.py", line 53, in run
pipe.wait()
File "/usr/lib/python2.4/subprocess.py", line 1007, in wait
pid, sts = os.waitpid(self.pid, 0)
OSError: [Errno 10] No child processes P.S. Googling for "[Errno 10] No child processes" suggests others have this problem. There have been long discussions on the Zope list as to why some people on Linux get exceptions that look like this, for example. |
As an additional note, I have also reproduced the popen problem using Python 2.4.4, though only once. |
If you are seeing a bug in subprocess, please report it separately. This one has been fixed. Please don't assume that it is the "same" problem as the one reported here, unless you have a working patch that proves that it is indeed a similar problem. |
From the original description: "Related modules: A seemingly related error occurs with I can be confident it is the same problem as I have used the exact As I added, I have also reproduced the "popen" problem using Python 2.4.4 once, though I can report separately if you really want, but it seems odd when the symptoms and test case |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: