slightly improved polling for ipc messaging.

workspace
Brendan Howell 8 years ago
parent 2ac3ba6ecb
commit f55733eb3f

@ -1,28 +0,0 @@
Babel==1.3
CairoSVG==1.0.13
Jinja2==2.7.3
Mako==1.0.1
MarkupSafe==0.23
Pygments==2.0.2
Pyphen==0.9.1
Sphinx==1.3.1
TheScreenlessOffice==0.1
WeasyPrint==0.23
alabaster==0.7.3
cairocffi==0.6
cffi==0.9.2
cssselect==0.9.1
docutils==0.12
evdev==0.4.7
html2text==2015.4.14
html5lib==0.99999
lxml==3.4.4
pycparser==2.13
pytz==2015.2
pyzmq==14.5.0
screenless==0.1
six==1.9.0
snowballstemmer==1.2.0
sphinx-rtd-theme==0.1.7
tinycss==0.3
twitter==1.17.0

@ -109,12 +109,19 @@ class Bureau(object):
sender.connect("ipc://" + recipient + ".ipc")
sender.send_string(message)
# TODO: retry this a few times with a proper sleep/timeout
time.sleep(0.5)
try:
ret = json.loads(sender.recv_string(flags=zmq.NOBLOCK))
# TODO: deal with non-json replies
except zmq.ZMQError:
print("message sent but got no reply...")
#time.sleep(0.5)
#try:
# ret = json.loads(sender.recv_string(flags=zmq.NOBLOCK))
# # TODO: deal with non-json replies
#except zmq.ZMQError:
# print("message sent but got no reply...")
# ret = None
events = sender.poll(timeout=10000)
if events is not 0:
ret = json.loads(sender.recv_string())
else:
print("message sent... timed out after 10 seconds.")
ret = None
return ret
@ -244,8 +251,11 @@ class Bureau(object):
# catch TypeErrors for case of bogus params
try:
if ref in self.api:
data = json.loads(data)
ret = self.api[ref](data)
if data:
data = json.loads(data)
ret = json.dumps(self.api[ref](data))
else:
ret = json.dumps(self.api[ref]())
else:
if data:
ret = self.commands[ref](data)

@ -15,7 +15,7 @@ while True:
print("sending ", msg[2:])
ret = None
trys = 0
while (not ret) and (trys < 10):
while (not ret) and (trys < 200):
try:
ret = send.recv(flags=zmq.NOBLOCK)
print("got", ret)
@ -23,5 +23,5 @@ while True:
trys += 1
time.sleep(0.05)
if not ret:
print("Error: timeout after 0.5 sec")
print("Error: timeout after 10 sec")
send.close()

Loading…
Cancel
Save