client-barcode: Turn stdin reading to nonblocking, add autologout after 3 Minutes

This commit is contained in:
Sebastian Pipping 2011-10-17 23:19:21 +02:00
parent c532fdb551
commit d3b0a8fa4c
1 changed files with 12 additions and 4 deletions

View File

@ -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)