-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
36 lines (29 loc) · 1.05 KB
/
client.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
import sys
sys.path.append('../zerobot/python3')
import zerobot
import zmq
import threading
class SuperClient:
def __init__(self, ctx, connect_addr="tcp://localhost:5000"):
self.ctx = ctx
self.clients = {}
self.connect = connect_addr
def call(self, service, method, args, kwargs):
if not(service in self.clients.keys()):
self.add_client(service)
call = getattr(self.clients[service], method)
kwargs['timeout'] = 1
kwargs['block'] = False
try:
threading.Thread(target=call, args=args, kwargs=kwargs).run()
except Exception as ex:
print(ex)
def add_client(self, service):
if not(service in self.clients.keys()):
client = zerobot.Client("QtSpy-%s" % service, self.connect, service, ctx=self.ctx)
client.start(False)
try:
client.ping(-42, timeout=1, block=False)
except Exception:
print("Unable to join %s" % service)
self.clients[service] = client