-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-102983: queue.Queue - Adding Cancelling Support #102996
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
base: main
Are you sure you want to change the base?
Conversation
…be raised when blocking gets are cancelled
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Lib/queue.py
Outdated
class Cancelled(Exception): | ||
'Exception raised by Queue.get(block=True) when cancelled' |
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.
The pass
is redundant and docstrings should be triple quoted:)
class Cancelled(Exception): | |
'Exception raised by Queue.get(block=True) when cancelled' | |
class Cancelled(Exception): | |
'''Exception raised by Queue.get(block=True) when cancelled''' |
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.
Indeed, I simply wanted to keep the same style with which the Full
exception is written, just a couple of lines above.
Lines 23 to 25 in f2e5a6e
class Full(Exception): | |
'Exception raised by Queue.put(block=0)/put_nowait().' | |
pass |
Question:
- Shall we add also the same changes to
Full
?
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.
class Cancelled(Exception): | |
'Exception raised by Queue.get(block=True) when cancelled' | |
class Cancelled(Exception): | |
"""Exception raised by Queue.get(block=True) when cancelled.""" |
Furthermore, while we're at it, per PEP 257 (PEP-257) and widespread convention, docstrings must use triple double quotes and summary lines should be complete sentences that always end with a period.
…style Full has in the original code
This PR already "works" (see sample test script in #102983. Things which could be considered
To fully avoid having pending cancellations in any case, the current amount of (blocking) gets can be considered in def cancel(self, n=1):
with self.not_empty:
n = min(n, len(self.not_empty._waiters))
self.cancelling.release(n=n)
self.not_empty.notify(n=n) It would then depart from the similar behavior of |
Proposed draft PR for #102983