Re: collect data using threads

2005-06-14 Thread Peter Hansen
Toby Dickenson wrote: > 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 refere

Re: collect data using threads

2005-06-14 Thread James Tanis
Previously, on Jun 14, Peter Hansen said: # James Tanis wrote: # > I may be wrong here, but shouldn't you just use a stack, or in other # > words, use the list as a stack and just pop the data off the top. I # > believe there is a method pop() already supplied for you. # # Just a note on term

Re: collect data using threads

2005-06-14 Thread Kent Johnson
Qiangning Hong wrote: > I actually had considered Queue and pop() before I wrote the above code. > However, because there is a lot of data to get every time I call > get_data(), I want a more CPU friendly way to avoid the while-loop and > empty checking, and then the above code comes out. But I a

Re: collect data using threads

2005-06-14 Thread Toby Dickenson
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

Re: collect data using threads

2005-06-14 Thread Peter Hansen
Peter Hansen wrote: > James Tanis wrote: > >> I may be wrong here, but shouldn't you just use a stack, or in other >> words, use the list as a stack and just pop the data off the top. I >> believe there is a method pop() already supplied for you. > > Just a note on terminology here. I believe

Re: collect data using threads

2005-06-14 Thread Qiangning Hong
James Tanis wrote: > # > > > A class Collector, it spawns several threads to read from serial port. > # > > > Collector.get_data() will get all the data they have read since last > # > > > call. Who can tell me whether my implementation correct? > # > > > > # Here's the original code: > #

Re: collect data using threads

2005-06-14 Thread Peter Hansen
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_da

Re: collect data using threads

2005-06-14 Thread Peter Hansen
James Tanis wrote: > I may be wrong here, but shouldn't you just use a stack, or in other > words, use the list as a stack and just pop the data off the top. I > believe there is a method pop() already supplied for you. Just a note on terminology here. I believe the word "stack" generally ref

Re: collect data using threads

2005-06-14 Thread James Tanis
Previously, on Jun 14, Jeremy Jones said: # Kent Johnson wrote: # # > Peter Hansen wrote: # > # > > Qiangning Hong wrote: # > > # > > # > > > A class Collector, it spawns several threads to read from serial port. # > > > Collector.get_data() will get all the data they have read since last

Re: collect data using threads

2005-06-14 Thread Jeremy Jones
Kent Johnson wrote: Peter Hansen wrote: Qiangning Hong wrote: A class Collector, it spawns several threads to read from serial port. Collector.get_data() will get all the data they have read since last call. Who can tell me whether my implementation correct?

Re: collect data using threads

2005-06-14 Thread Kent Johnson
Peter Hansen wrote: > Qiangning Hong wrote: > >> A class Collector, it spawns several threads to read from serial port. >> Collector.get_data() will get all the data they have read since last >> call. Who can tell me whether my implementation correct? > > [snip sample with a list] > >> I am not

Re: collect data using threads

2005-06-14 Thread Peter Hansen
Qiangning Hong wrote: > A class Collector, it spawns several threads to read from serial port. > Collector.get_data() will get all the data they have read since last > call. Who can tell me whether my implementation correct? [snip sample with a list] > I am not very sure about the get_data() metho

Re: collect data using threads

2005-06-14 Thread Jeremy Jones
Qiangning Hong wrote: >A class Collector, it spawns several threads to read from serial port. >Collector.get_data() will get all the data they have read since last >call. Who can tell me whether my implementation correct? > >class Collector(object): >def __init__(self): >self.data = [