-
Notifications
You must be signed in to change notification settings - Fork 3
/
gui_datathread.py
52 lines (40 loc) · 1.16 KB
/
gui_datathread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Provides a thread to read data from grpc
"""
import grpc
import threading
import time
class DataThread(threading.Thread):
def __init__(self, name, gen):
threading.Thread.__init__(self)
self.name = name
self.gen = gen
self.recent_data = None
self.event = threading.Event()
self.paused = False
self.stopped = False
def run(self):
while not self.stopped:
self.recent_data = next(self.gen)
if self.paused:
self.event.wait()
# time.sleep(1)
def get_recent_data(self):
return self.recent_data
def stopCollection(self):
self.event.clear()
self.paused = True
def resumeCollection(self):
self.event.set()
self.paused = False
def isCollecting(self):
return (not self.stopped) and (not self.paused)
def stop(self):
# self.gen.close() # TODO close the generator?
self.event.set()
self.stopped = True
def updateRate(self, newRate):
pass
def updateGenerator(self, newGen):
# Used when the data transmission rate is changed
self.gen = newGen