8000 gh-96471: Add threading queue shutdown by EpicWink · Pull Request #104750 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-96471: Add threading queue shutdown #104750

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

Merged
Prev Previous commit
Next Next commit
More explicitly update 'q.unfinished_tasks'
  • Loading branch information
EpicWink committed Feb 9, 2024
commit e0927aae42f4c9032cb11cf68d8ba9c7af5e8dc0
4 changes: 2 additions & 2 deletions Lib/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ def shutdown(self, immediate=False):
n_items = self._qsize()
while self._qsize():
self._get()
self.unfinished_tasks = max(self.unfinished_tasks - n_items, 0)
if self.unfinished_tasks > 0:
self.unfinished_tasks -= 1
self.not_empty.notify_all()
# release all blocked threads in `join()`
self.all_tasks_done.notify_all()
self.not_full.notify_all()


# Override these methods to implement other queue organizations
# (e.g. stack or priority queue).
# These will only be called with appropriate locks held
Expand Down
0