collect data using threads
peter at engcorp.com
Tue Jun 14 18:47:55 CEST 2005
Kent Johnson wrote:
> Peter Hansen wrote:
>> That will not work, and you will get data loss, as Jeremy points out.
> Can you explain why not? self.data is still bound to the same list as x.
> At least if the execution sequence is x = self.data
> self.data = 
Ah, since the entire list is being returned, you appear to be correct.
Interesting... this means the OP's code is actually appending things to
a list, over and over (presumably), then returning a reference to that
list and rebinding the internal variable to a new list. If another
thread calls on_received() and causes new data to be appended to "the
list" between those two statements, then it will show up in the returned
list (rather magically, at least to my way of looking at it) and will
not in fact be lost.
Good catch Kent. :-)
More information about the Python-list