Skip to content

Negative run-time reported by subprocess.run's TimeoutExpired exception when setting timeout=0 #133089

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vadimkantorov opened this issue Apr 28, 2025 · 1 comment · May be fixed by #133103
Open
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-subprocess Subprocess issues. type-bug An unexpected behavior, bug, or error

Comments

@vadimkantorov
Copy link

vadimkantorov commented Apr 28, 2025

Bug report

Bug description:

import subprocess
subprocess.run(['echo', 'hi'], timeout = 0)

# subprocess.TimeoutExpired: Command '['echo', 'hi']' timed out after -0.00010189996100962162 seconds
# subprocess.TimeoutExpired: Command '['echo', 'hi']' timed out after -4.819990135729313e-05 seconds

This is quite unexpected that the measured run-time can be negative

In general, it's unclear in the docs what behavior should have timeout=0. I would propose that it should disable timeout control, and should be equivalent to timeout=None.

But in any case, negative run-times are quite strange :)

CPython versions tested on:

3.12

Operating systems tested on:

WSLv1+Ubuntu24.04

Linked PRs

@vadimkantorov vadimkantorov added the type-bug An unexpected behavior, bug, or error label Apr 28, 2025
@picnixz picnixz added stdlib Python modules in the Lib dir topic-subprocess Subprocess issues. labels Apr 28, 2025
Zheaoli added a commit to Zheaoli/cpython that referenced this issue Apr 28, 2025
…ut=None' when the timeout is zero

Signed-off-by: Manjusaka <me@manjusaka.me>
@vadimkantorov
Copy link
Author

Btw, even outside of unspecified behavior for timeout=0, setting timeout to a very small value also prints negative time measurement:

import subprocess
subprocess.run(['echo', 'hi'], timeout = 1e-9)

# subprocess.TimeoutExpired: Command '['echo', 'hi']' timed out after -2.162200007660431e-05 seconds

How can time measurement be negative? Is it indicative of some other bug related to execution time measurement?

@ZeroIntensity ZeroIntensity added 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-subprocess Subprocess issues. type-bug An unexpected behavior, bug, or error
Projects
None yet
3 participants