-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
33 lines (27 loc) · 1002 Bytes
/
worker.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
from rpyc import Service
from rpyc.utils.server import ThreadedServer
from importlib import import_module
import traceback
import socket
from threading import Thread
class WaitForServicesService(Service):
def start_thread(self, service):
s = ThreadedServer(service, auto_register=True)
print(f"Started {service.__name__}")
s.start()
def exposed_add_service(self, service):
try:
module = import_module(service)
service_thread = Thread(target=self.start_thread, args=[module._default])
service_thread.start()
return True
except Exception:
print(f"Unable to create service {service}")
traceback.print_exc()
return False
def exposed_get_hostname(self):
return socket.gethostname()
print("Waiting on services")
run_loop = ThreadedServer(WaitForServicesService, auto_register=True)
run_loop.start()
# TODO: Handle cleanup/deregistration on remote stub close