python iterators and thread-safety
- by Igor
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:
def updateWidgets(self):
widgets = self.generateWidgetList()
self.widgets = widgets
the other function deals with the widgets in some way:
def workOnWidgets(self):
for widget in self.widgets:
self.workOnWidget(widget)
each of these functions runs in it's own thread. the question is, what happens if the updateWidgets() thread executes while the workOnWidgets() thread is running?
I am assuming that the iterator created as part of the for...in loop will keep some kind of reference to the old self.widgets object? So I will finish iterating over the old list... but I'd love to know for sure.