From 2570d3c450f17f83eb39edaf7f975153952ceda6 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 1 Jun 2018 00:53:53 -0400 Subject: [PATCH] More fix --- NodeInstance.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/NodeInstance.py b/NodeInstance.py index b0c34de9..4f2a4f87 100644 --- a/NodeInstance.py +++ b/NodeInstance.py @@ -53,7 +53,25 @@ class NodeInstance(threading.Thread): def run(self): if self.name == socket.gethostname(): - self.setup_local_node() + conn = self.setup_local_node() + + while True: + if self.name == socket.gethostname(): + self.memfree = conn.getFreeMemory() + self.cpuload = os.getloadavg()[0] + 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,100): + time.sleep(0.1) + if self.stop_thread.is_set(): + return @zk.DataWatch(self.zkey + '/state') def watch_state(data, stat): @@ -93,20 +111,4 @@ class NodeInstance(threading.Thread): print("Node hostname: %s" % self.name) print("CPUs: %s" % self.cpucount) - while True: - self.memfree = conn.getFreeMemory() - self.cpuload = os.getloadavg()[0] - 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,100): - time.sleep(0.1) - if self.stop_thread.is_set(): - return - + return conn