Skip to content
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

bpo-32576: use queue.SimpleQueue in critical places #5216

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/concurrent/futures/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, max_workers=None, thread_name_prefix='',
raise TypeError("initializer must be a callable")

self._max_workers = max_workers
self._work_queue = queue.Queue()
self._work_queue = queue.SimpleQueue()
self._threads = set()
self._broken = False
self._shutdown = False
Expand Down
19 changes: 11 additions & 8 deletions Lib/multiprocessing/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def __init__(self, processes=None, initializer=None, initargs=(),
maxtasksperchild=None, context=None):
self._ctx = context or get_context()
self._setup_queues()
self._taskqueue = queue.Queue()
self._taskqueue = queue.SimpleQueue()
self._cache = {}
self._state = RUN
self._maxtasksperchild = maxtasksperchild
Expand Down Expand Up @@ -802,15 +802,18 @@ def __init__(self, processes=None, initializer=None, initargs=()):
Pool.__init__(self, processes, initializer, initargs)

def _setup_queues(self):
self._inqueue = queue.Queue()
self._outqueue = queue.Queue()
self._inqueue = queue.SimpleQueue()
self._outqueue = queue.SimpleQueue()
self._quick_put = self._inqueue.put
self._quick_get = self._outqueue.get

@staticmethod
def _help_stuff_finish(inqueue, task_handler, size):
# put sentinels at head of inqueue to make workers finish
with inqueue.not_empty:
inqueue.queue.clear()
inqueue.queue.extend([None] * size)
inqueue.not_empty.notify_all()
# drain inqueue, and put sentinels at its head to make workers finish
try:
while True:
inqueue.get(block=False)
except queue.Empty:
pass
for i in range(size):
inqueue.put(None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use queue.SimpleQueue() in places where it can be invoked from a weakref
callback.