Skip to content

Commit 3b6651a

Browse files
committed
Merge pull request #12 from zhangkaizhao/master
fix set name of polling threads. compatible with py3k.
2 parents ee41a87 + 78f5d95 commit 3b6651a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

zktop.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@
1919
from optparse import OptionParser
2020

2121
import curses
22-
import threading, Queue
22+
import threading
23+
try:
24+
import Queue
25+
except ImportError: # py3
26+
import queue as Queue
2327
import socket
2428
import signal
25-
import re, StringIO
29+
import re
30+
try:
31+
import StringIo
32+
except ImportError: # py3
33+
from io import StringIO
2634
import logging as LOG
2735

2836
ZK_DEFAULT_PORT = 2181
@@ -169,7 +177,7 @@ def __init__(self, win):
169177
global mainwin
170178
self.maxy, self.maxx = mainwin.getmaxyx()
171179
self.resize(self.maxy, self.maxx)
172-
180+
173181
def resize(self, maxy, maxx):
174182
LOG.debug("resize called y %d x %d" % (maxy, maxx))
175183
self.maxy = maxy
@@ -241,7 +249,7 @@ def update(self, s):
241249
items = []
242250
for l in self.sessions:
243251
items.extend(l)
244-
items.sort(lambda x,y: int(y.queued)-int(x.queued))
252+
items.sort(key=lambda x: int(x.queued), reverse=True)
245253
for i, session in enumerate(items):
246254
try:
247255
#ugh, need to handle if slow - thread for async resolver?
@@ -278,7 +286,7 @@ def show_ui(self, stdscr):
278286
# start the polling threads
279287
pollers = [StatPoller(server) for server in self.servers]
280288
for poller in pollers:
281-
poller.setName("PollerThread:" + server)
289+
poller.setName("PollerThread:" + poller.server)
282290
poller.setDaemon(True)
283291
poller.start()
284292

@@ -355,7 +363,7 @@ def read_zk_config(filename):
355363
k,v = tuple(line.replace(' ', '').strip().split('=', 1))
356364
config[k] = v
357365
except IOError as e:
358-
print "Unable to open `{0}': I/O error({1}): {2}".format(filename, e.errno, e.strerror)
366+
print("Unable to open `{0}': I/O error({1}): {2}".format(filename, e.errno, e.strerror))
359367
finally:
360368
f.close()
361369
return config

0 commit comments

Comments
 (0)