diff options
| author | Victor Stinner <vstinner@python.org> | 2024-03-19 13:42:44 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-19 13:42:44 (GMT) |
| commit | 27cf3ed00cfe942f4277c273a3dda8ee2ba61fc8 (patch) | |
| tree | 18d2811b50c3e556e680c3fd91db7f39b8a57b2a /Lib/test/test_subprocess.py | |
| parent | 408e127159e54d87bb3464fd8bd60219dc527fac (diff) | |
| download | cpython-27cf3ed00cfe942f4277c273a3dda8ee2ba61fc8.zip cpython-27cf3ed00cfe942f4277c273a3dda8ee2ba61fc8.tar.gz cpython-27cf3ed00cfe942f4277c273a3dda8ee2ba61fc8.tar.bz2 | |
gh-90872: Fix subprocess.Popen.wait() for negative timeout (#116989)
On Windows, subprocess.Popen.wait() no longer calls
WaitForSingleObject() with a negative timeout: pass 0 ms if the
timeout is negative.
Diffstat (limited to 'Lib/test/test_subprocess.py')
| -rw-r--r-- | Lib/test/test_subprocess.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index c44a778..d20b987 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1607,6 +1607,22 @@ class ProcessTestCase(BaseTestCase): self.assertIsInstance(subprocess.Popen[bytes], types.GenericAlias) self.assertIsInstance(subprocess.CompletedProcess[str], types.GenericAlias) + @unittest.skipUnless(hasattr(subprocess, '_winapi'), + 'need subprocess._winapi') + def test_wait_negative_timeout(self): + proc = subprocess.Popen(ZERO_RETURN_CMD) + with proc: + patch = mock.patch.object( + subprocess._winapi, + 'WaitForSingleObject', + return_value=subprocess._winapi.WAIT_OBJECT_0) + with patch as mock_wait: + proc.wait(-1) # negative timeout + mock_wait.assert_called_once_with(proc._handle, 0) + proc.returncode = None + + self.assertEqual(proc.wait(), 0) + class RunFuncTestCase(BaseTestCase): def run_python(self, code, **kwargs): |
