-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatmoEventThread.py
More file actions
67 lines (48 loc) · 2.12 KB
/
atmoEventThread.py
File metadata and controls
67 lines (48 loc) · 2.12 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Import python modules
import multiprocessing
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# Import user modules
import unity_server as server
#------------------------------------------------------------------------------#
class AtmoEventStream:
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def __init__(self, message_pool):
# initialize the video camera stream and read the first frame
# from the stream
self.stream = server
self._message_pool = message_pool
# self.message = self.stream.receive()
# initialize the variable used to indicate if the thread should
# be stopped
self.stopped = self.unread = False
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def start(self):
# start the thread to read frames from the video stream
# Thread(target=self.update, args=()).start()
thread = multiprocessing.Process(target=self.update, args=())
thread.daemon = False
thread.start()
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def update(self):
# keep looping infinitely until the thread is stopped
while True:
# if the thread indicator variable is set, stop the thread
if self.stopped:
return self.stream.close()
# otherwise, read the next frame from the stream
self._message_pool.put(self.stream.receive())
# print('NEW')
self.unread = True
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def read(self):
# return the frame most recently read
if self.unread:
self.unread = False
# print('READ')
return self.message
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def close(self):
# indicate that the thread should be stopped
self.stopped = True