gh-90872: Fix subprocess.Popen.wait() for negative timeout by vstinner · Pull Request #116989 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/subprocess.py
16 changes: 16 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,22 @@ def test_class_getitems(self):
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):
Expand Down