-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Make threading.Event().wait(timeout=3) return isSet #44660
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
Comments
Currently the wait method on threading.Event always returns None, even if a timeout is given and the event is not set. x.wait(3)
if x.isSet():
# do stuff Note that in the above case, the event could be cleared between the return from x.wait and the execution of x.isSet (in another thread), and so this would operate as though x.wait had just timed out It would be great to be able to do: if x.wait(3):
# do stuff This should also not affect any existing code as it shouldn't be relying on the return value from x.wait anyway |
This one-line change to threading.py makes Event.wait() return isSet(). |
Tim, you said this was a bad idea for conditions in bpo-1175933 - is the |
I would like to add my support for this change. As David described, it |
I agree this would be a worthwhile addition too. Unfortunately given the |
A test should be added to the patch, and then I think it could go in. |
Thanks, Antoine. I will re-check the patch against trunk and add tests |
Looking at this, I think this change is fine. The _Event class itself e.wait()
if e.is_set():
GOT_IT() over if e.wait():
GOT_IT() IOW Tim's reasoning in bpo-1175933 for rejecting a similar change to |
Added a pony test and committed in r70883. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: