[Python-checkins] Add multiprocessing.Pool.__repr__() (GH-11137)

Victor Stinner webhook-mailer at python.org
Fri Dec 14 05:13:24 EST 2018


https://github.com/python/cpython/commit/2b417fba25f036c2d6139875e389d80e4286ad75
commit: 2b417fba25f036c2d6139875e389d80e4286ad75
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-12-14T11:13:18+01:00
summary:

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

files:
M Lib/multiprocessing/pool.py

diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index c0775418852d..cede9bbd5d40 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -30,9 +30,9 @@
 # Constants representing the state of a pool
 #
 
-RUN = 0
-CLOSE = 1
-TERMINATE = 2
+RUN = "RUN"
+CLOSE = "CLOSE"
+TERMINATE = "TERMINATE"
 
 #
 # Miscellaneous
@@ -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.
@@ -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:
@@ -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":
                 assert thread._state == TERMINATE, "Thread not in TERMINATE"
                 util.debug('result handler found thread._state=TERMINATE')
                 break



More information about the Python-checkins mailing list