-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-125997: ensure that time.sleep(0)
is not delayed on non-Windows platforms
#128274
base: main
Are you sure you want to change the base?
Conversation
ff959e1
to
80de853
Compare
@picnixz Unfortunately, we should seriously review :(. It seems that an assertion failed somewhere.
|
Ah I think I know what happens. When we raise an OSError from errno we don't clear the errno. So if you chain calls, you need to just ignore them. I'm removing the assertion cc @ZeroIntensity |
Due to how `OSError` are raised from `errno`, we do not clear `errno` afterwards. If we catch `OSError`, then we still have an errno set, and if we call `time.sleep()` just after, we may have `errno != 0` (but we know we handled it so it's fine).
If pytime is running on multiple cores, I recommend using raw defined
|
This wouldn't solve the issue (also because |
TIL! Should we assert |
Not sure. It's not really an issue and the function is internal and only for |
I think we should. There's no real cost to adding it, and it would be helpful for debugging in the rare case that something goes wrong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linking #28111 for other reviewers
I'd vote we can get rid of the do-while, I think it would only matter if monotonic is not monotonic
I'd also vote we don't backport. This is basically a performance optimisation (which we don't typically backport) for a regression that has only been reported once in two years and that has an easy workaround.
struct timeval zero = {0, 0}; | ||
Py_BEGIN_ALLOW_THREADS | ||
ret = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &zero); | ||
err = errno; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can get rid of err
, seems like an artifact of the version of this code that has a bunch of #ifdef
I wanted to be sure that "PyTime_Monotonic() != -1" means that "monotonic > deadline" but if this is guaranteed, then I'd be happy to simplify the code.
I'm also fine with this (I just treated it as a regular bug fix but we can treat it as a performance feature). The workaround you're talking about is to use |
Yes, using |
This is a suggestion for fixing the issue when the timeout is 0. For other timeouts, this does not change the current behaviour (I'm tempted removing the
do-while
loop as we should never have an issue, but I'm not familar with the monotonic C implementation so I left it as is).time.sleep(0)
regression in 3.11 onwards #125997