threading - race condition?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri May 9 01:42:35 EDT 2008
En Fri, 09 May 2008 01:30:32 -0300, skunkwerk <skunkwerk at gmail.com>
escribió:
> On May 8, 4:54 pm, castiro... at gmail.com wrote:
>> On May 8, 5:45 pm, skunkwerk <skunkw... at gmail.com> wrote:
>>
>>
>>
>> > 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 workerthreads(100) and a queue into which
>> > new requests are inserted, like so:
>>
>> > 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?
>>
>> If man arises as a tool-carrier, we will carry tools, not people.
>> Don't use Python to make people; make money, and not too much. Pick a
>> wage and you might get somewhere.
>
> excuse me?
(Please forgive our local pet)
is "item" a list? Perhaps the *same* list as other requests? Be careful
when you put mutable objects in a queue.
And what about domain.get_item? is it a thread safe operation?
You said the model is not a global - but is it a *different* object for
each request?
--
Gabriel Genellina
More information about the Python-list
mailing list