threading - race condition?

skunkwerk skunkwerk at gmail.com
Thu May 8 18:45:45 EDT 2008


i'm getting the wrong output for the 'title' attributes for this
data.  the queue holds a data structure (item name, position, and list
to store results in).  each thread takes in an item name and queries a
database for various attributes.  from the debug statements the item
names are being retrieved correctly, but the attributes returned are
those of other items in the queue - not its own item.  however, the
model variable is not a global variable... so i'm not sure what's
wrong.

i've declared a bunch of worker threads (100) and a queue into which
new requests are inserted, like so:

queue = Queue.Queue(0)
 WORKERS=100
for i in range(WORKERS):
	thread = SDBThread(queue)
	thread.setDaemon(True)
	thread.start()

the thread:

class SimpleDBThread ( threading.Thread ):
   def __init__ ( self, queue ):
		self.__queue = queue
		threading.Thread.__init__ ( self )
   def run ( self ):
		while 1:
			item = self.__queue.get()
			if item!=None:
				model = domain.get_item(item[0])
				logger.debug('sdbthread item:'+item[0])
				title = model['title']
				scraped = model['scraped']
				logger.debug("sdbthread title:"+title)

any suggestions?
thanks



More information about the Python-list mailing list