Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133089: Use original timeout value forTimeoutExpired when the funcsubprocess.run is called with a timeout#133103

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 17 commits intopython:mainfromZheaoli:manjusaka/fix-subproces-timeout
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
update docs
Signed-off-by: Manjusaka <me@manjusaka.me>
  • Loading branch information
@Zheaoli
Zheaoli committedMay 3, 2025
commit5f746ee827968278c309779da3324ff7b7a0dbd6
10 changes: 6 additions & 4 deletionsLib/subprocess.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2031,7 +2031,7 @@ def _wait(self, timeout):
if self.returncode is not None:
return self.returncode

if timeout is not None and timeout > 0:
if timeout is not None:
endtime = _time() + timeout
# Enter a busy loop if we have a timeout. This busy loop was
# cribbed from Lib/threading.py in Thread.wait() at r71065.
Expand All@@ -2049,7 +2049,7 @@ def _wait(self, timeout):
finally:
self._waitpid_lock.release()
remaining = self._remaining_time(endtime)
if remaining < 0:
if remaining <= 0:
raise TimeoutExpired(self.args, timeout)
delay = min(delay * 2, remaining, .05)
time.sleep(delay)
Expand DownExpand Up@@ -2145,8 +2145,10 @@ def _communicate(self, input, endtime, orig_timeout):
selector.unregister(key.fileobj)
key.fileobj.close()
self._fileobj2output[key.fileobj].append(data)

self.wait(timeout=self._remaining_time(endtime))
try:
self.wait(timeout=self._remaining_time(endtime))
except TimeoutExpired:
raise TimeoutExpired(self.args, orig_timeout)

# All data exchanged. Translate lists into strings.
if stdout is not None:
Expand Down
2 changes: 0 additions & 2 deletionsLib/test/test_subprocess.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1660,8 +1660,6 @@ def test_timeout(self):
# child.
with self.assertRaises(subprocess.TimeoutExpired):
self.run_python("while True: pass", timeout=0.0001)
def test_timeout_zero(self):
self.run_python("import time; time.sleep(0.1)", timeout=0)

def test_capture_stdout(self):
# capture stdout with zero return code
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
Make :func:`subprocess.run`'s behavior is same with 'timeout=None' when
thetimeoutiszero
Use origional timeout value for :exc:`TimeoutExpired`
whenthefunc :meth:`subprocess.run`iscalled with a timeout
Loading

[8]ページ先頭

©2009-2025 Movatter.jp