working queue
This commit is contained in:
parent
7f4626445c
commit
e51a9e044c
30
tracker.py
30
tracker.py
@ -6,29 +6,43 @@ class Tracker(Process):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._queue = Queue()
|
self._queue = Queue()
|
||||||
Process.__init__(self, args=(self._queue,))
|
Process.__init__(self, args=(self._queue,))
|
||||||
self._quit = Event()
|
self._stop = Event()
|
||||||
self._quit.clear()
|
self._finished = Event()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print("Running")
|
print("Running")
|
||||||
while not self._quit.is_set():
|
while not self._stop.is_set():
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
self._queue.put([1,2,3,4,5,"lkj"])
|
||||||
|
self._finished.set()
|
||||||
print("Closing")
|
print("Closing")
|
||||||
|
|
||||||
|
def start_acquisition(self):
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def stop_acquisition(self):
|
||||||
|
self._stop.set()
|
||||||
|
|
||||||
def get_result(self):
|
def get_result(self):
|
||||||
pass
|
self._stop.set()
|
||||||
|
while not self._finished.is_set():
|
||||||
|
time.sleep(0.1)
|
||||||
|
return self._queue.get()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self._quit.set()
|
self._stop.set() # just to make sure
|
||||||
|
self.join()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
p = Tracker()
|
p = Tracker()
|
||||||
try:
|
try:
|
||||||
p.start()
|
p.start_acquisition()
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
p.shutdown()
|
p.stop_acquisition()
|
||||||
|
a = p.get_result()
|
||||||
|
print("Result is: ", a)
|
||||||
finally:
|
finally:
|
||||||
p.join()
|
p.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user