From 7bcb2e0b00a0994808ab6c0a2dc685eba82e8083 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 1 Jun 2018 00:35:39 -0400 Subject: [PATCH] Fix up some more bugs --- NodeInstance.py | 11 ++++++++--- pvcd.py | 11 ++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index d252e5cf..b0646cf3 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -77,11 +77,16 @@ class NodeInstance(threading.Thread): while True: self.memfree = conn.getFreeMemory() self.cpuload = os.getloadavg()[0] - self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) - self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii')) + try: + self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii')) + self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii')) + except: + if self.stop_thread.is_set(): + return + print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload )) print("Active domains: %s" % self.domainlist) - for x in range(0,50): + for x in range(0,100): time.sleep(0.1) if self.stop_thread.is_set(): return diff --git a/pvcd.py b/pvcd.py index 5c2c5c74..66c1320b 100755 --- a/pvcd.py +++ b/pvcd.py @@ -43,9 +43,11 @@ myhostname = socket.gethostname() mynodestring = '/nodes/%s' % myhostname def cleanup(): - zk.set('%s/state' % mynodestring, 'stop'.encode('ascii')) - for node in node_list: - t_node[node].stop() + t_node[myhostname].stop() + try: + zk.set('/nodes/' + myhostname + '/state', 'stop'.encode('ascii')) + except: + pass zk.stop() atexit.register(cleanup) @@ -76,9 +78,8 @@ def updatenodes(new_node_list): t_node[node].updatenodelist(node_list) else: t_node[node] = NodeInstance.NodeInstance(node, node_list, zk); - if t_node[node].name == myhostname: + if node == myhostname: t_node[node].start() - time.sleep(1) node_state = t_node[node].getstate() if node_state == 'start':