-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwrapMicrophones.py
More file actions
executable file
·68 lines (57 loc) · 1.52 KB
/
wrapMicrophones.py
File metadata and controls
executable file
·68 lines (57 loc) · 1.52 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
68
# script to wrap up the microphones in python
import Pyro4
import time, os, sys
import threading
import signal
class ffserver(object):
def __init__(self):
"""Sets up the ffserver class"""
self._running=True
self._lock=threading.Lock()
def startThread(self,thread_name):
"""Start one of the various threads available"""
if thread_name=="ffserver":
ffserver_runloop=threading.Thread(target=self.run_ffserver_thread)
ffserver_runloop.daemon=True
ffserver_runloop.start()
elif thread_name=="pyro":
pyro_runloop=threading.Thread(target=self.run_pyro_thread)
pyro_runloop.daemon=True
pyro_runloop.start()
else:
print("Invalid thread_name")
def run_ffserver_thread(self):
"""Run the ffserver in a separate thread"""
os.popen('/usr/local/bin/ffserver -f /home/ops/ngts/ffserver/ffserver.conf')
def run_pyro_thread(self):
"""Run the pyro in a separate thread"""
hub=Pyro4.Proxy("PYRONAME:central.hub")
while(self._running):
hub.report_in('microphones')
time.sleep(10)
def stop(self):
"""Stop the daemon thread"""
self._running = False
# set up Ctrl+C handling
die=False
def signal_handler(signal,frame):
global die
print "Ctrl+C caught, exiting..."
die=True
signal.signal(signal.SIGINT,signal_handler)
def main():
ff=ffserver()
ff.startThread("ffserver")
py=ffserver()
py.startThread("pyro")
while(1):
time.sleep(5)
# close up
if die == True:
ff.stop()
print ("Stopping ffserver")
py.stop()
print ("Stopping pyro")
sys.exit(1)
if __name__ == '__main__':
main()