Skip to content
Merged
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
16 changes: 11 additions & 5 deletions Lib/multiprocessing/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
# Constants representing the state of a pool
#

RUN = 0
CLOSE = 1
TERMINATE = 2
RUN = "RUN"
CLOSE = "CLOSE"
TERMINATE = "TERMINATE"

#
# Miscellaneous
Expand Down Expand Up @@ -217,6 +217,12 @@ def __init__(self, processes=None, initializer=None, initargs=(),
exitpriority=15
)

def __repr__(self):
cls = self.__class__
return (f'<{cls.__module__}.{cls.__qualname__} '
f'state={self._state} '
f'pool_size={len(self._pool)}>')

def _join_exited_workers(self):
"""Cleanup after any worker processes which have exited due to reaching
their specified lifetime. Returns True if any workers were cleaned up.
Expand Down Expand Up @@ -432,7 +438,7 @@ def _handle_tasks(taskqueue, put, outqueue, pool, cache):
try:
# iterating taskseq cannot fail
for task in taskseq:
if thread._state:
if thread._state != RUN:
util.debug('task handler found thread._state != RUN')
break
try:
Expand Down Expand Up @@ -480,7 +486,7 @@ def _handle_results(outqueue, get, cache):
util.debug('result handler got EOFError/OSError -- exiting')
return

if thread._state:
if thread._state != "RUN":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@vstinner, @ulfalizer mentioned on 2b417fb that this may have meant to be RUN, not "RUN"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oops! Fixed by PR #11178.

assert thread._state == TERMINATE, "Thread not in TERMINATE"
util.debug('result handler found thread._state=TERMINATE')
break
Expand Down