Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b417fb

Browse files
authored
Add multiprocessing.Pool.__repr__() (GH-11137)
* Add multiprocessing.Pool.__repr__() to ease debug * RUN, CLOSE and TERMINATE constants values are now strings rather than integer to ease debug
1 parent afb3e71 commit 2b417fb

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/multiprocessing/pool.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
# Constants representing the state of a pool
3131
#
3232

33-
RUN = 0
34-
CLOSE = 1
35-
TERMINATE = 2
33+
RUN = "RUN"
34+
CLOSE = "CLOSE"
35+
TERMINATE = "TERMINATE"
3636

3737
#
3838
# Miscellaneous
@@ -217,6 +217,12 @@ def __init__(self, processes=None, initializer=None, initargs=(),
217217
exitpriority=15
218218
)
219219

220+
def __repr__(self):
221+
cls = self.__class__
222+
return (f'<{cls.__module__}.{cls.__qualname__} '
223+
f'state={self._state} '
224+
f'pool_size={len(self._pool)}>')
225+
220226
def _join_exited_workers(self):
221227
"""Cleanup after any worker processes which have exited due to reaching
222228
their specified lifetime. Returns True if any workers were cleaned up.
@@ -432,7 +438,7 @@ def _handle_tasks(taskqueue, put, outqueue, pool, cache):
432438
try:
433439
# iterating taskseq cannot fail
434440
for task in taskseq:
435-
if thread._state:
441+
if thread._state != RUN:
436442
util.debug('task handler found thread._state != RUN')
437443
break
438444
try:
@@ -480,7 +486,7 @@ def _handle_results(outqueue, get, cache):
480486
util.debug('result handler got EOFError/OSError -- exiting')
481487
return
482488

483-
if thread._state:
489+
if thread._state != "RUN":
484490
assert thread._state == TERMINATE, "Thread not in TERMINATE"
485491
util.debug('result handler found thread._state=TERMINATE')
486492
break

0 commit comments

Comments
 (0)