This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients rosslagerwall, vinay.sajip
Date 2012-02-21.22:56:50
SpamBayes Score 3.8276826e-11
Marked as misclassified No
Message-id <1329865011.81.0.762834414848.issue14079@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-02-21 22:56:51vinay.sajipsetrecipients: + vinay.sajip, rosslagerwall
2012-02-21 22:56:51vinay.sajipsetmessageid: <1329865011.81.0.762834414848.issue14079@psf.upfronthosting.co.za>
2012-02-21 22:56:51vinay.sajiplinkissue14079 messages
2012-02-21 22:56:50vinay.sajipcreate