Fix zmq.green not handling zmq.RCVTIMEO in python 2.7 examples

This commit is contained in:
AnthorNet 2016-01-07 14:03:37 +01:00
parent 6e7b6b8b96
commit 7cc1e74130
2 changed files with 142 additions and 123 deletions

View File

@ -7,10 +7,11 @@ import sys, os, datetime, time
" Configuration
"""
__relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500'
__timeoutEDDN = 600000
#__timeoutEDDN = 600000 # 10 minuts
__timeoutEDDN = 60000 # 1 minut
# Set False to listen to production stream
__debugEDDN = True;
# Set False to listen to production stream; True to listen to debug stream
__debugEDDN = False;
# Set to False if you do not want verbose logging
__logVerboseFile = os.path.dirname(__file__) + '/Logs_Verbose_EDDN_%DATE%.htm'
@ -27,7 +28,8 @@ __authorisedSoftwares = [
"EliteOCR",
"Maddavo's Market Share",
"RegulatedNoise",
"RegulatedNoise__DJ"
"RegulatedNoise__DJ",
"E:D Market Connector [Windows]"
]
# Used this to excludes yourself for example has you don't want to handle your own messages ^^
@ -100,16 +102,14 @@ def main():
echoLog('')
echoLog('')
poller = zmq.Poller()
poller.register(subscriber, zmq.POLLIN)
while True:
__message = subscriber.recv()
if __message == False:
subscriber.disconnect(__relayEDDN)
echoLog('Disconnect from ' + __relayEDDN)
echoLog('')
echoLog('')
break
socks = dict(poller.poll(__timeoutEDDN))
if socks:
if socks.get(subscriber) == zmq.POLLIN:
__message = subscriber.recv(zmq.NOBLOCK)
__message = zlib.decompress(__message)
__json = simplejson.loads(__message)
__converted = False
@ -204,15 +204,24 @@ def main():
echoLog('')
del __converted
else:
print 'Disconnect from ' + __relayEDDN + ' (After timeout)'
echoLog('')
echoLog('')
sys.stdout.flush()
subscriber.disconnect(__relayEDDN)
break
except zmq.ZMQError, e:
echoLog('')
echoLog('ZMQSocketException: ' + str(e))
subscriber.disconnect(__relayEDDN)
echoLog('Disconnect from ' + __relayEDDN)
echoLog('')
time.sleep(5)
echoLog('Disconnect from ' + __relayEDDN + ' (After receiving ZMQError)')
echoLog('ZMQSocketException: ' + str(e))
echoLog('')
time.sleep(10)

View File

@ -8,7 +8,8 @@ import time
" Configuration
"""
__relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500'
__timeoutEDDN = 600000
#__timeoutEDDN = 600000 # 10 minuts
__timeoutEDDN = 60000 # 1 minut
@ -20,31 +21,40 @@ def main():
subscriber = context.socket(zmq.SUB)
subscriber.setsockopt(zmq.SUBSCRIBE, "")
subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
while True:
try:
subscriber.connect(__relayEDDN)
print 'Connect to EDDN'
sys.stdout.flush()
poller = zmq.Poller()
poller.register(subscriber, zmq.POLLIN)
while True:
__message = subscriber.recv()
if __message == False:
subscriber.disconnect(__relayEDDN)
break
socks = dict(poller.poll(__timeoutEDDN))
if socks:
if socks.get(subscriber) == zmq.POLLIN:
__message = subscriber.recv(zmq.NOBLOCK)
__message = zlib.decompress(__message)
__json = simplejson.loads(__message)
print __json
sys.stdout.flush()
else:
print 'Disconnect from EDDN (After timeout)'
sys.stdout.flush()
subscriber.disconnect(__relayEDDN)
break
except zmq.ZMQError, e:
print 'Disconnect from EDDN (After receiving ZMQError)'
print 'ZMQSocketException: ' + str(e)
sys.stdout.flush()
subscriber.disconnect(__relayEDDN)
time.sleep(5)
time.sleep(10)