Repository navigation
Expand file tree
/
Copy pathRemote.py
More file actions
85 lines (60 loc) · 2.05 KB
/
Copy pathRemote.py
File metadata and controls
85 lines (60 loc) · 2.05 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
# @author: RaNaN
import threading
import traceback
class BackendBase(threading.Thread):
def __init__(self, manager):
threading.Thread.__init__(self)
self.m = manager
self.core = manager.core
self.enabled = True
self.running = False
def run(self):
self.running = True
try:
self.serve()
except Exception, e:
self.core.log.error(_("Remote backend error: %s") % e)
if self.core.debug:
traceback.print_exc()
finally:
self.running = False
def setup(self, host, port):
pass
def checkDeps(self):
return True
def serve(self):
pass
def shutdown(self):
pass
def stop(self):
self.enabled = False #: set flag and call shutdowm message, so thread can react
self.shutdown()
class RemoteManager(object):
available = []
def __init__(self, core):
self.core = core
self.backends = []
if self.core.remote:
self.available.append("ThriftBackend")
# else:
# self.available.append("SocketBackend")
def startBackends(self):
host = self.core.config.get("remote", "listenaddr")
port = self.core.config.get("remote", "port")
for b in self.available:
klass = getattr(__import__("pyload.remote.%s" % b, globals(), locals(), [b], -1), b)
backend = klass(self)
if not backend.checkDeps():
continue
try:
backend.setup(host, port)
self.core.log.info(_("Starting %(name)s: %(addr)s:%(port)s") % {"name": b, "addr": host, "port": port})
except Exception, e:
self.core.log.error(_("Failed loading backend %(name)s | %(error)s") % {"name": b, "error": str(e)})
if self.core.debug:
traceback.print_exc()
else:
backend.start()
self.backends.append(backend)
port += 1