remove unused threader class

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3182 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2006-05-15 18:02:07 +00:00
parent 70fedc052c
commit c8bcdf7d79

View file

@ -71,78 +71,3 @@ def set_thread_priority (prio):
res = None
return res
class Threader (object):
"""
A thread generating class. Note that since Python has no ability to
stop threads from outside, one has to make sure threads poll
regularly for outside variables to stop them. Or one makes sure
threads surely will terminate in finite time.
"""
def __init__ (self, num=5):
"""
Store maximum number of threads to generate, and initialize
an empty thread list.
"""
# this allows negative numbers
self.threads_max = max(num, 0)
# list of active threads to watch
self.threads = []
def _acquire (self):
"""
Wait until we are allowed to start a new thread.
"""
while self.active_threads() >= self.threads_max:
self._reduce_threads()
time.sleep(0.1)
def _reduce_threads (self):
"""
Remove inactive threads.
"""
self.threads = [ t for t in self.threads if t.isAlive() ]
def active_threads (self):
"""
Return number of active threads.
"""
return len(self.threads)
def finished (self):
"""
Return True if no active threads are left.
"""
if self.threads_max > 0:
self._reduce_threads()
return self.active_threads() == 0
def finish (self):
"""
Remove inactive threads.
"""
self._reduce_threads()
def start_thread (self, func, args, name=None):
"""
Generate a new thread.
"""
if self.threads_max < 1:
# threading is disabled
func(*args)
else:
self._acquire()
# thread names must be ASCII to avoid conversion problems
assert isinstance(name, str) or name is None, \
"Invalid name %r" % name
t = threading.Thread(None, func, name, args)
t.start()
self.threads.append(t)
def __str__ (self):
"""
String representation of threader state.
"""
return "Threader with %d threads (max %d)" % \
(self.active_threads(), self.threads_max)