X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fthreadpool.py;h=f1b68ce2e9bb4088222e2b0227a9793fafadafcd;hb=af77a12a601851c96357d6313407e1da91a66830;hp=5b17e3c496c5e99959badedc2c97402a5572eb5d;hpb=9ea7dd5f4a515bc0e68f8267a2db9e80bdcdd81e;p=dak.git diff --git a/daklib/threadpool.py b/daklib/threadpool.py index 5b17e3c4..f1b68ce2 100644 --- a/daklib/threadpool.py +++ b/daklib/threadpool.py @@ -1,19 +1,21 @@ -import threading -from time import sleep +""" +thread pool implementation for Python -from daklib.config import Config +@contact: Debian FTPMaster +@copyright: 2003 Tim Lesher +@copyright: 2004 Carl Kleffner +@copyright: 2010, 2011 Torsten Werner +""" # 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. -# Ensure booleans exist (not needed for Python 2.2.1 or higher) -try: - True -except NameError: - False = 0 - True = not False +import threading +from time import sleep + +from daklib.config import Config if Config().has_key('Common::ThreadCount'): defaultThreadCount = int(Config()['Common::ThreadCount']) @@ -131,14 +133,15 @@ class ThreadPool: # Tell all the threads to quit self.__resizeLock.acquire() try: - self.__setThreadCountNolock(0) - self.__isJoining = True - # Wait until all threads have exited if waitForThreads: + for t in self.__threads: + t.goAway() for t in self.__threads: t.join() del t + self.__setThreadCountNolock(0) + self.__isJoining = True # Reset the pool for potential reuse self.__isJoining = False