[Tutor] Threading weirdness

Steve steve@funkyjesus.net
Thu, 17 Oct 2002 16:33:37 +0100


Hi,
I'm having some real problems with some threading. Here's the particular snippet
that's giving me grief:

while self.queue and (self.numThreads < self.maxThreads):
	target = self.queue.pop()
	ret = Worker(target)
	print "adding thread " + str(self.numThreads) + "/" + str(self.maxThreads) + "\n"
	ret.start()
	self.threadList.append(ret)
	self.numThreads = self.numThreads + 1

	tmpNumThreads = self.numThreads
		for ret in self.threadList[:] :
			if ret.done:
				self.threadList.remove(ret)
				self.numThreads = self.numThreads - 1
		if tmpNumThreads == self.numThreads:
			time.sleep(1)

Now self.maxThreads is supplied as an argument that I'm pulling from getopt.
That works fine, but what happens is regardless of the size of maxThreads it
just keeps on going until it's finished, adding threads as it goes.

I must be doing something blatantly wrong here, could someone please point out
what it is!

Thanks,
Steve

-- 
I have spent most of my money on women and beer. The rest I just wasted...