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

List:       python-list
Subject:    Re: collect data using threads
From:       Toby Dickenson <tdickenson () devmail ! geminidataloggers ! co ! uk>
Date:       2005-06-14 17:06:24
Message-ID: 200506141806.24706.tdickenson () devmail ! geminidataloggers ! co ! uk
[Download RAW message or body]

On Tuesday 14 June 2005 17:47, Peter Hansen wrote:
> 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.

But it might not "show up" until too late.

The consumer thread that called get_data presumably does something with that 
list, such as iterating over its contents. It might only "show up" after that 
iteration has finished, when the consumer has discarded its reference to the 
shared list.

-- 
Toby Dickenson
-- 
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