diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 3f67de2..eff1bb5 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -18,6 +18,7 @@ from decimal import Decimal import os import time import urllib2 +import select from thread import start_new_thread, allocate_lock import time @@ -514,6 +515,7 @@ class Status: def print_prompt(): sys.stdout.write(">>> ") + sys.stdout.flush() def handle(line, status): @@ -561,6 +563,15 @@ def handle(line, status): error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) +def read_line(f, timeout, timeout_func): + ready_to_read, _, _ = select.select([f], [], [], timeout) + if ready_to_read: + return f.readline().rstrip() + else: + timeout_func() + return '' + + def main(): colorama.init() status = Status() @@ -575,10 +586,7 @@ def main(): clear() status.dump() print_prompt() - l = sys.stdin.readline() - if not l: - break - line = l.rstrip() + line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout) if line: print_display('\x0cBarcode:\n%20s' % line[:20]) handle(line, status)