threading: getting latest elements from list/dict

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue May 6 00:16:10 EDT 2008


En Mon, 05 May 2008 08:26:45 -0300, Vaibhav.bhawsar  
<bhawsar.vaibhav at gmail.com> escribió:

> Hello
> I have a thread updating a dictionary with new elements. How can I check  
> for
> new elements as they are inserted into the dictionary by the thread? In
> general is it safe to read a dictionary or a list while it is being  
> updated
> by a running thread? Does the dictionary or list have to be locked while
> reading?
> many questions! :)

Use a Queue object to communicate between threads. The language itself  
doesn't guarantee anything about atomicity.
You might put the new elements in a queue, and make the consumer update  
the dictionary instead of the producer.


-- 
Gabriel Genellina




More information about the Python-list mailing list