mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-10 20:32:15 +03:00
Fix zmq.green not handling zmq.RCVTIMEO in python 2.7 examples
This commit is contained in:
parent
6e7b6b8b96
commit
7cc1e74130
@ -7,10 +7,11 @@ import sys, os, datetime, time
|
|||||||
" Configuration
|
" Configuration
|
||||||
"""
|
"""
|
||||||
__relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500'
|
__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
|
# Set False to listen to production stream; True to listen to debug stream
|
||||||
__debugEDDN = True;
|
__debugEDDN = False;
|
||||||
|
|
||||||
# Set to False if you do not want verbose logging
|
# Set to False if you do not want verbose logging
|
||||||
__logVerboseFile = os.path.dirname(__file__) + '/Logs_Verbose_EDDN_%DATE%.htm'
|
__logVerboseFile = os.path.dirname(__file__) + '/Logs_Verbose_EDDN_%DATE%.htm'
|
||||||
@ -27,7 +28,8 @@ __authorisedSoftwares = [
|
|||||||
"EliteOCR",
|
"EliteOCR",
|
||||||
"Maddavo's Market Share",
|
"Maddavo's Market Share",
|
||||||
"RegulatedNoise",
|
"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 ^^
|
# 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('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
|
poller = zmq.Poller()
|
||||||
|
poller.register(subscriber, zmq.POLLIN)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
__message = subscriber.recv()
|
socks = dict(poller.poll(__timeoutEDDN))
|
||||||
|
if socks:
|
||||||
if __message == False:
|
if socks.get(subscriber) == zmq.POLLIN:
|
||||||
subscriber.disconnect(__relayEDDN)
|
__message = subscriber.recv(zmq.NOBLOCK)
|
||||||
echoLog('Disconnect from ' + __relayEDDN)
|
|
||||||
echoLog('')
|
|
||||||
echoLog('')
|
|
||||||
break
|
|
||||||
|
|
||||||
__message = zlib.decompress(__message)
|
__message = zlib.decompress(__message)
|
||||||
__json = simplejson.loads(__message)
|
__json = simplejson.loads(__message)
|
||||||
__converted = False
|
__converted = False
|
||||||
@ -204,15 +204,24 @@ def main():
|
|||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
del __converted
|
del __converted
|
||||||
|
else:
|
||||||
|
print 'Disconnect from ' + __relayEDDN + ' (After timeout)'
|
||||||
|
echoLog('')
|
||||||
|
echoLog('')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
subscriber.disconnect(__relayEDDN)
|
||||||
|
break
|
||||||
|
|
||||||
except zmq.ZMQError, e:
|
except zmq.ZMQError, e:
|
||||||
echoLog('')
|
|
||||||
echoLog('ZMQSocketException: ' + str(e))
|
|
||||||
subscriber.disconnect(__relayEDDN)
|
subscriber.disconnect(__relayEDDN)
|
||||||
echoLog('Disconnect from ' + __relayEDDN)
|
|
||||||
echoLog('')
|
echoLog('')
|
||||||
time.sleep(5)
|
echoLog('Disconnect from ' + __relayEDDN + ' (After receiving ZMQError)')
|
||||||
|
echoLog('ZMQSocketException: ' + str(e))
|
||||||
|
echoLog('')
|
||||||
|
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ import time
|
|||||||
" Configuration
|
" Configuration
|
||||||
"""
|
"""
|
||||||
__relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500'
|
__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 = context.socket(zmq.SUB)
|
||||||
|
|
||||||
subscriber.setsockopt(zmq.SUBSCRIBE, "")
|
subscriber.setsockopt(zmq.SUBSCRIBE, "")
|
||||||
subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
subscriber.connect(__relayEDDN)
|
subscriber.connect(__relayEDDN)
|
||||||
|
print 'Connect to EDDN'
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
poller = zmq.Poller()
|
||||||
|
poller.register(subscriber, zmq.POLLIN)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
__message = subscriber.recv()
|
socks = dict(poller.poll(__timeoutEDDN))
|
||||||
|
if socks:
|
||||||
if __message == False:
|
if socks.get(subscriber) == zmq.POLLIN:
|
||||||
subscriber.disconnect(__relayEDDN)
|
__message = subscriber.recv(zmq.NOBLOCK)
|
||||||
break
|
|
||||||
|
|
||||||
__message = zlib.decompress(__message)
|
__message = zlib.decompress(__message)
|
||||||
__json = simplejson.loads(__message)
|
__json = simplejson.loads(__message)
|
||||||
|
|
||||||
|
|
||||||
print __json
|
print __json
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
else:
|
||||||
|
print 'Disconnect from EDDN (After timeout)'
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
subscriber.disconnect(__relayEDDN)
|
||||||
|
break
|
||||||
|
|
||||||
except zmq.ZMQError, e:
|
except zmq.ZMQError, e:
|
||||||
|
print 'Disconnect from EDDN (After receiving ZMQError)'
|
||||||
print 'ZMQSocketException: ' + str(e)
|
print 'ZMQSocketException: ' + str(e)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
subscriber.disconnect(__relayEDDN)
|
subscriber.disconnect(__relayEDDN)
|
||||||
time.sleep(5)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user