Unverified Kaydet (Commit) 2b417fba authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

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
üst afb3e71a
...@@ -30,9 +30,9 @@ from . import get_context, TimeoutError ...@@ -30,9 +30,9 @@ from . import get_context, TimeoutError
# Constants representing the state of a pool # Constants representing the state of a pool
# #
RUN = 0 RUN = "RUN"
CLOSE = 1 CLOSE = "CLOSE"
TERMINATE = 2 TERMINATE = "TERMINATE"
# #
# Miscellaneous # Miscellaneous
...@@ -217,6 +217,12 @@ class Pool(object): ...@@ -217,6 +217,12 @@ class Pool(object):
exitpriority=15 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): def _join_exited_workers(self):
"""Cleanup after any worker processes which have exited due to reaching """Cleanup after any worker processes which have exited due to reaching
their specified lifetime. Returns True if any workers were cleaned up. their specified lifetime. Returns True if any workers were cleaned up.
...@@ -432,7 +438,7 @@ class Pool(object): ...@@ -432,7 +438,7 @@ class Pool(object):
try: try:
# iterating taskseq cannot fail # iterating taskseq cannot fail
for task in taskseq: for task in taskseq:
if thread._state: if thread._state != RUN:
util.debug('task handler found thread._state != RUN') util.debug('task handler found thread._state != RUN')
break break
try: try:
...@@ -480,7 +486,7 @@ class Pool(object): ...@@ -480,7 +486,7 @@ class Pool(object):
util.debug('result handler got EOFError/OSError -- exiting') util.debug('result handler got EOFError/OSError -- exiting')
return return
if thread._state: if thread._state != "RUN":
assert thread._state == TERMINATE, "Thread not in TERMINATE" assert thread._state == TERMINATE, "Thread not in TERMINATE"
util.debug('result handler found thread._state=TERMINATE') util.debug('result handler found thread._state=TERMINATE')
break break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment