-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
bpo-32243: Use monotonic clock for thread timeouts; more flexibility for very small switch intervals #4964
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
Conversation
This doesn't compile on macOS.
|
The use of |
…ed amount in case it is so short (especially on slow systems) that the deadline is always in the past
Rebased in current master (though it was a clean merge) and added a configure-time check for I'm not sure what is the best way to update the |
@embray If you have an |
I think this should do. There were some other minor differences that were unrelated to the change and easily excluded. |
monotonic clock is implemented in #11723 |
@methane Please reopen, as I think you've partially misunderstood the purpose of this PR, which is to fix this issue https://bugs.python.org/issue32243 , where the GIL can get stuck if The issue is fixed most effectively by using the monotomic clock, which is why this PR includes it, but that isn't actually the main point of it. That's great that #11723 finally added the monotonic clock support, so I can just rebase this PR now, and it will make the actual bug fix more readily apparent. AFAICT #11723 on its own does not address this issue. |
I know you tried to solve different issue. I didn't reject issue32243. |
I would suggest to write a new pull request written on top of the master branch. I would be interested to read it :-) |
Seems odd to just close but okay. I can make a new PR since it would be slightly different insofar as not including the clock_monotonic updates themselves. |
This is the work I did toward fixing bpo-32243 (and might be better broken into separate PRs--we'll see).
This updates @vstinner's patch from bpo-23428, and on top of it adds a fix to
PyCOND_TIMEDWAIT
that makes small adjustments, if needed, to the timeout (in microseconds) if it's so short that the deadline is always in the past.My experience in profiling the latter fix (just with some print statements) was that on a slow VM, with setting
sys.setswitchinterval(1e-6)
on a slow system, this would typically go through the while loop I added toPyCOND_TIMEDWAIT
twice (i.e. it would increase the timeout once). On rarer occasions it would go through three times. Withsys.setswitchinterval(1e-5)
it would sometimes go through the loop twice--usually just once. And for longer switch intervals than that it would always go through the loop only once.This does all unfortunately come at the cost of an unconditional extra call
GETTIME()
.https://bugs.python.org/issue32243