Skip to content

Commit

Permalink
tweaks to eddn listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Jan 30, 2015
1 parent e417bc2 commit 0d9ad68
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions misc/eddn.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ def connect(self):
Start a connection
"""
# tear up the new connection first
if self.subscriber:
self.subscriber.close()
del self.subscriber
self.subscriber = newsub = self.zmqContext.socket(zmq.SUB)
newsub.setsockopt(zmq.SUBSCRIBE, b"")
newsub.connect(self.uri)
self.lastRecv = time.time()
self.lastJsData = None


def disconnect(self):
Expand Down Expand Up @@ -196,6 +200,8 @@ def get_batch(self, onerror=None):
built-in auto-reconnection if there is nothing from the
firehose for a period of time.
As json data is decoded, it is stored in self.lastJsData.
Parameters:
onerror
None or a function/lambda that takes an error
Expand Down Expand Up @@ -233,6 +239,7 @@ def get_batch(self, onerror=None):
# we reach the burst limit or we get EAGAIN.
bursts = 0
for _ in range(self.burstLimit):
self.lastJsData = None
try:
zdata = sub.recv(flags=zmq.NOBLOCK, copy=False)
stats['recvs'] += 1
Expand All @@ -259,6 +266,8 @@ def get_batch(self, onerror=None):
onerror("json.loads: %s: %s"%(type(e), e))
continue

self.lastJsData = jsdata

try:
schema = data["$schemaRef"]
except KeyError:
Expand Down

0 comments on commit 0d9ad68

Please sign in to comment.