From 4e4634b525875b0799b59ea94dfbdd3c27532a35 Mon Sep 17 00:00:00 2001 From: Lulu Pac Date: Wed, 16 Sep 2015 23:37:32 +0200 Subject: [PATCH] fixed issue #541, also fixed same issue in clonesrv6.py --- examples/Python/clonesrv5.py | 7 ++++--- examples/Python/clonesrv6.py | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/Python/clonesrv5.py b/examples/Python/clonesrv5.py index 21acc94cc..96f38b616 100644 --- a/examples/Python/clonesrv5.py +++ b/examples/Python/clonesrv5.py @@ -109,8 +109,8 @@ def handle_collect(self, msg): self.sequence += 1 kvmsg.sequence = self.sequence kvmsg.send(self.publisher) - ttl = kvmsg.get('ttl') - if ttl is not None: + ttl = float(kvmsg.get('ttl', 0)) + if ttl: kvmsg['ttl'] = time.time() + ttl kvmsg.store(self.kvmap) logging.info("I: publishing update=%d", self.sequence) @@ -123,7 +123,8 @@ def flush_ttl(self): def flush_single(self, kvmsg): """If key-value pair has expired, delete it and publish the fact to listening clients.""" - if kvmsg.get('ttl', 0) <= time.time(): + ttl = float(kvmsg.get('ttl', 0)) + if ttl and ttl <= time.time(): kvmsg.body = "" self.sequence += 1 kvmsg.sequence = self.sequence diff --git a/examples/Python/clonesrv6.py b/examples/Python/clonesrv6.py index f02420513..4938cdb86 100644 --- a/examples/Python/clonesrv6.py +++ b/examples/Python/clonesrv6.py @@ -142,7 +142,7 @@ def handle_collect(self, msg): self.sequence += 1 kvmsg.sequence = self.sequence kvmsg.send(self.publisher) - ttl = int(kvmsg.get('ttl')) + ttl = float(kvmsg.get('ttl', 0)) if ttl: kvmsg['ttl'] = time.time() + ttl kvmsg.store(self.kvmap) @@ -175,7 +175,7 @@ def flush_ttl(self): def flush_single(self, kvmsg): """If key-value pair has expired, delete it and publish the fact to listening clients.""" - ttl = int(kvmsg.get('ttl')) + ttl = float(kvmsg.get('ttl', 0)) if ttl and ttl <= time.time(): kvmsg.body = "" self.sequence += 1 @@ -256,9 +256,9 @@ def handle_subscriber(self, msg): # Find and remove update off pending list kvmsg = KVMsg.from_msg(msg) - # update integer ttl -> timestamp - ttl = int(kvmsg.get('ttl')) - if ttl is not None: + # update float ttl -> timestamp + ttl = float(kvmsg.get('ttl', 0)) + if ttl: kvmsg['ttl'] = time.time() + ttl if kvmsg.key != "HUGZ":