[New-bugs-announce] [issue14079] Problems with recent test_subprocess changes

Vinay Sajip report at bugs.python.org
Tue Feb 21 23:56:51 CET 2012


New submission from Vinay Sajip <vinay_sajip at yahoo.co.uk>:

There appears to be a problem with a recent change made to test_subprocess to try and speed it up a bit. The commit with a problem seems to be 834650d63130 by Ross Lagerwall on 12 Feb 2012, and the problem is in test_poll(), which now looks like this:

    def test_poll(self):
        p = subprocess.Popen([sys.executable, "-c",
                              "import os",
                              "os.read(1)"], stdin=subprocess.PIPE)
        self.addCleanup(p.stdin.close)
        self.assertIsNone(p.poll())
        os.write(p.stdin.fileno(), b'A')
        p.wait()
        # Subsequent invocations should just return the returncode
        self.assertEqual(p.poll(), 0)

A number of problems here: -c only takes one parameter, so for example

./python -c "import os" "os.read(1)"

never does anything with the "os.read(1)". Possibly

"import os; os.read(1)"

was meant, but that doesn't work either: os.read takes two parameters, fd and n, so it seems that what is wanted is

"import os; os.read(0, 1)"

which appears to fulfill the intent to read a byte from stdin.

Because the command being run is effectively

python -c "import os"

the spawned command returns immediately. This (it would appear) leads to a race between the test process and the spawned process, such that sometimes the poll() returns None and sometimes it returns 0, due to the vagaries of the exact circumstances when the test is run. So the test passes on some machines but not on others.

It looks like it would be good to change the Popen call to use "import os; os.read(0, 1)" as the "-c" parameter value.

----------
messages: 153912
nosy: rosslagerwall, vinay.sajip
priority: normal
severity: normal
status: open
title: Problems with recent test_subprocess changes
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14079>
_______________________________________


More information about the New-bugs-announce mailing list