-
Notifications
You must be signed in to change notification settings - Fork 0
/
Infernos.py
93 lines (76 loc) · 2.59 KB
/
Infernos.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from getopt import getopt, GetoptError
import os, sys
import ray
from sippy.misc import daemonize
from sippy.SipLogger import SipLogger
sys.path.append('.')
from SIP.InfernUA import InfernSIPConf
from Cluster.InfernSIPActor import InfernSIPActor
from Core.InfernConfig import InfernConfig
def patch_signals():
import threading
import signal
def _start_new_thread(*args):
allsigs = list(signal.valid_signals())
old_sigset = signal.pthread_sigmask(signal.SIG_BLOCK, allsigs)
ret = _old_start_new_thread(*args)
signal.pthread_sigmask(signal.SIG_SETMASK, old_sigset)
return ret
_old_start_new_thread = threading._start_new_thread
threading._start_new_thread = _start_new_thread
if __name__ == '__main__':
try:
opts, args = getopt(sys.argv[1:], 'fL:i:')
except GetoptError:
print('usage: Infernos.py [-f] [-L logfile] [-i pidfile] config.yaml')
sys.exit(1)
idir = os.path.realpath(sys.argv[0])
idir = os.path.dirname(idir)
sys.path.append(idir)
authname = None
authpass = None
logfile = '/var/log/Infernos.log'
pidfile = None
foreground = False
for o, a in opts:
if o == '-f':
foreground = True
elif o == '-L':
logfile = a
# elif o == '-n':
# if a.startswith('['):
# parts = a.split(']', 1)
# iua_c.nh_addr = [parts[0] + ']', 5060]
# parts = parts[1].split(':', 1)
# else:
# parts = a.split(':', 1)
# iua_c.nh_addr = [parts[0], 5060]
# if len(parts) == 2:
# iua_c.nh_addr[1] = int(parts[1])
elif o == '-i':
pidfile = a
if not foreground:
daemonize(logfile)
patch_signals()
if logfile == '-':
lfile = sys.stdout
else:
lfile = open(logfile, 'a')
default_resources = InfernSIPActor.default_resources
default_resources['live_translator'] = 1
default_resources['tts'] = 2
default_resources['stt'] = 1
try:
ray.init(num_gpus=1, resources = default_resources)
except ValueError as ex:
if str(ex).index('connecting to an existing cluster') < 0: raise ex
ray.init()
inf_c = InfernConfig('config.yaml')
if pidfile != None:
open(pidfile, 'w').write('%d' % os.getpid())
inf_c.sip_conf.logger = SipLogger('Infernos', logfile = os.path.expanduser('~/.Infernos.log'))
try:
exit(ray.get(inf_c.sip_actr.loop.remote(inf_c)))
except KeyboardInterrupt:
ray.get(inf_c.sip_actr.stop.remote())
raise