summaryrefslogtreecommitdiffstats
path: root/table-data
diff options
context:
space:
mode:
Diffstat (limited to 'table-data')
-rwxr-xr-xtable-data41
1 files changed, 22 insertions, 19 deletions
diff --git a/table-data b/table-data
index 2206e0e..e67e31a 100755
--- a/table-data
+++ b/table-data
@@ -4,6 +4,7 @@
from sys import stdin, argv
import cStringIO,operator
from threading import Timer, RLock
+from time import time
def indent(rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
separateRows=False, prefix='', postfix='', wrapfunc=lambda x:x):
@@ -79,28 +80,30 @@ def wrap_always(text, width):
if __name__ == '__main__':
- def timer(lock, data):
- with lock:
- data.append[False]
+ if len(argv) > 1:
+ sep = argv[1]
+ else:
+ sep = ','
+ timeout = 10.0
+ tries, max_tries = 0, 3
- lock = RLock()
- ret, data = True, [True]
+ while tries < max_tries:
+ ret, data = '', []
+ start = time()
- while ret and (not len(data) or data[-1] != ''): # EOF
- t = Timer(15, timer, args=(lock, data))
- while ret and data[-1]:
+ # until timeout or EOF (read may block pass the timeout!)
+ while (time() - start) < timeout:
ret = stdin.readline()
- #print "read", ret
- with lock:
- if not isinstance(data[-1], str):
- data = data[:-1]
- data.append(ret)
- t.cancel()
- #if not isinstance(data[-1], str):
- # data = data[:-1]
- sep = ','
- if len(argv) > 1:
- sep = argv[1]
+ if not ret:
+ break
+ data.append(ret)
+
+ if not ret:
+ tries += 1
+ else:
+ tries = 0
+ if not data:
+ continue
rows = [row.strip().split(sep) for row in data]
#print 'Without wrapping function\n'