cascadeadmin status: wait for threads
authorMarko Kreen <markokr@gmail.com>
Sun, 3 Mar 2013 19:00:50 +0000 (21:00 +0200)
committerMarko Kreen <markokr@gmail.com>
Sun, 3 Mar 2013 19:00:50 +0000 (21:00 +0200)
Instead Queue.join(), call Thread.join() for each
thread.  Otherwise the thread can be active during
process shutdown and throw weird errors.

After that, calling Queue.join() seems useless; it can
even allow additional failure situations.

Also clarify thread count logic.

python/pgq/cascade/admin.py

index e7ac86059dfc395a2dff53fdf1f75cb78429f0b5..dd9215d8f38a8fbb5783e22238e4f7705a03125a 100644 (file)
@@ -422,12 +422,17 @@ class CascadeAdmin(skytools.AdminScript):
         nodes = Queue.Queue()
 
         # launch workers and wait
-        n = max (min (members.qsize() >> 2, 100), 1)
-        for i in range(n):
+        num_nodes = len(self.queue_info.member_map)
+        num_threads = max (min (num_nodes / 4, 100), 1)
+        tlist = []
+        for i in range(num_threads):
             t = threading.Thread (target = self._cmd_status_worker, args = (members, nodes))
             t.daemon = True
             t.start()
-        members.join()
+            tlist.append(t)
+        #members.join()
+        for t in tlist:
+            t.join()
 
         while True:
             try: