]> git.decadent.org.uk Git - dak.git/commitdiff
Merge remote branch 'twerner/msfl' into merge
authorJoerg Jaspert <joerg@debian.org>
Sun, 4 Jul 2010 20:20:27 +0000 (22:20 +0200)
committerJoerg Jaspert <joerg@debian.org>
Sun, 4 Jul 2010 20:20:27 +0000 (22:20 +0200)
* twerner/msfl:
  introduce defaultThreadCount
  add key Common::ThreadCount to dak.conf

Signed-off-by: Joerg Jaspert <joerg@debian.org>
config/debian/dak.conf
daklib/threadpool.py

index 0f8e3fe269e86c1478ae7730c7b26a3f70010648..16120d8eb9dcefa8be65057feab9df069551fa50 100644 (file)
@@ -653,3 +653,9 @@ Contents
   Header "contents";
   Root "/srv/ftp-master.debian.org/test/";
 }
+
+Common
+{
+  // The default number of threads for multithreading parts of dak:
+  ThreadCount 16;
+}
index 95a14a34de99218c97c2754418970d64fdb34a77..5b17e3c496c5e99959badedc2c97402a5572eb5d 100644 (file)
@@ -1,16 +1,13 @@
 import threading
 from time import sleep
 
+from daklib.config import Config
+
 # This code is a modified copy of
 # http://code.activestate.com/recipes/203871-a-generic-programming-thread-pool/
 # and is licensed under the Python License. The full text of the license
 # is available in the file COPYING-PSF.
 
-# FIXME:
-# numThreads defaults to 16 in __init__ to work best on
-# franck.debian.org but the default value should be specified in
-# dak.conf
-
 # Ensure booleans exist (not needed for Python 2.2.1 or higher)
 try:
     True
@@ -18,16 +15,25 @@ except NameError:
     False = 0
     True = not False
 
+if Config().has_key('Common::ThreadCount'):
+    defaultThreadCount = int(Config()['Common::ThreadCount'])
+else:
+    defaultThreadCount = 1
+
 class ThreadPool:
 
     """Flexible thread pool class.  Creates a pool of threads, then
-    accepts tasks that will be dispatched to the next available
-    thread."""
+    accepts tasks that will be dispatched to the next available thread.
+    The argument numThreads defaults to 'Common::ThreadCount' which must
+    be specified in dak.conf."""
 
-    def __init__(self, numThreads = 16):
+    def __init__(self, numThreads = 0):
 
         """Initialize the thread pool with numThreads workers."""
 
+        if numThreads == 0:
+            numThreads = defaultThreadCount
+
         self.__threads = []
         self.__resizeLock = threading.Condition(threading.Lock())
         self.__taskLock = threading.Condition(threading.Lock())