title: python iterators and thread-safety
body: <p>I have a class which is being operated on by two functions. One function creates a list of widgets and writes it into the class:</p>
  
  <pre><code>def updateWidgets(self):
     widgets = self.generateWidgetList()
     self.widgets = widgets
  </code></pre>
  
  <p>the other function deals with the widgets in some way:</p>
  
  <pre><code>def workOnWidgets(self):
     for widget in self.widgets:
        self.workOnWidget(widget)
  </code></pre>
  
  <p>each of these functions runs in it's own thread. the question is, what happens if the <code>updateWidgets()</code> thread executes while the <code>workOnWidgets()</code> thread is running?</p>
  
  <p>I am assuming that the iterator created as part of the <code>for...in</code> loop will keep some kind of reference to the <em>old</em> self.widgets object? So I will finish iterating over the old list... but I'd love to know for sure.</p>