[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: collect data using threads
From:       Peter Hansen <peter () engcorp ! com>
Date:       2005-06-14 16:47:55
Message-ID: 4q2dneNoafbYljLfRVn-sQ () powergate ! ca
[Download RAW message or body]

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.append(a_piece_of_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. :-)

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic