From 57619bfe35eba89e6b0f2d2383e91590ff156763 Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Sun, 4 Jul 2010 18:37:55 +0200 Subject: [PATCH] add key Common::ThreadCount to dak.conf That is the default number of threads created for the ThreadPool() but the value can be overwritten when calling the constructor. Signed-off-by: Torsten Werner --- config/debian/dak.conf | 6 ++++++ daklib/threadpool.py | 14 ++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/config/debian/dak.conf b/config/debian/dak.conf index 5252788b..2eaccd76 100644 --- a/config/debian/dak.conf +++ b/config/debian/dak.conf @@ -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; +} diff --git a/daklib/threadpool.py b/daklib/threadpool.py index 95a14a34..41ae3431 100644 --- a/daklib/threadpool.py +++ b/daklib/threadpool.py @@ -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 @@ -21,10 +18,11 @@ except NameError: 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 = Config()['Common::ThreadCount']): """Initialize the thread pool with numThreads workers.""" -- 2.39.5