Skip to content

bpo-24882: eagerly spawn threads in ThreadPoolExecutor#6530

Closed
iUnknwn wants to merge 1 commit intopython:masterfrom
iUnknwn:fix-issue-24882-rev2
Closed

bpo-24882: eagerly spawn threads in ThreadPoolExecutor#6530
iUnknwn wants to merge 1 commit intopython:masterfrom
iUnknwn:fix-issue-24882-rev2

Conversation

@iUnknwn
Copy link
Copy Markdown
Contributor

@iUnknwn iUnknwn commented Apr 19, 2018

This is an alternate solution to issue 24882 (and a replacement for PR #6375). At the suggestion
of @pitrou , instead of implementing idle thread handling logic, this change modifies ThreadPoolExecutor to spawn all worker threads on creation - removing all the logic entirely.

Also updates relevant test cases.

https://bugs.python.org/issue24882

This is an alternate solution to issue 24882. At the suggestion
of pitrou, instead of implementing idle thread handling logic,
this change modifies ThreadPoolExecutor to spawn all worker threads
on creation.
thread_name = '%s_%d' % (self._thread_name_prefix or self,
thread_num)
t = threading.Thread(name=thread_name, target=_worker,
args=(weakref.ref(self, weakref_cb),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the weakref shared among all threads?
If weakref_cb can call q.put(None) max_workers times. Or we can use __del__ method for it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there is no need to call q.put(None) max_workers times.
First worker received None calls q.put(None) for next worker.

# Notice other workers
work_queue.put(None)

@pitrou
Copy link
Copy Markdown
Member

pitrou commented May 20, 2019

Closing in favor of #6375.

@pitrou pitrou closed this May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants