collect data using threads

2005-06-14 Thread Qiangning Hong
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 = []

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 = []

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() method.

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 very sure

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 #call.

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 refers

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_data)

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: # # class

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 the word

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 = self.data

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 am

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

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 reference to