mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-01 21:50:25 +00:00
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:
parent
70fedc052c
commit
c8bcdf7d79
1 changed files with 0 additions and 75 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue