forked from naisy/realtime_object_detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpio.py
53 lines (49 loc) · 1.11 KB
/
mpio.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
53
import threading
import time
from lib.mpvariable import MPVariable
def start_receiver(in_con, q, mp_drop_frames):
"""
START THREAD
"""
t = threading.Thread(target=receive, args=(in_con, q, mp_drop_frames,))
t.setDaemon(True)
t.start()
return t
def receive(in_con, q, mp_drop_frames):
"""
READ CONNECTION TO QUEUE
"""
while True:
data = in_con.recv()
if data is None:
q.put(data)
break
if q.empty():
q.put(data)
else:
mp_drop_frames.value += 1
in_con.close()
return
def start_sender(out_con, q):
"""
START THREAD
"""
t = threading.Thread(target=send, args=(out_con, q, ))
t.setDaemon(True)
t.start()
return t
def send(out_con, q):
"""
READ QUEUE TO CONNECTION
"""
while True:
in_time = time.time()
data = q.get(block=True)
q.task_done()
out_con.send(data)
out_time = time.time()
MPVariable.send_proc_time.value = out_time - in_time
if data is None:
break
out_con.close()
return