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 os
import time import time
import urllib2 import urllib2
import select
from thread import start_new_thread, allocate_lock from thread import start_new_thread, allocate_lock
import time import time
@ -514,6 +515,7 @@ class Status:
def print_prompt(): def print_prompt():
sys.stdout.write(">>> ") sys.stdout.write(">>> ")
sys.stdout.flush()
def handle(line, status): def handle(line, status):
@ -561,6 +563,15 @@ def handle(line, status):
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e)) 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(): def main():
colorama.init() colorama.init()
status = Status() status = Status()
@ -575,10 +586,7 @@ def main():
clear() clear()
status.dump() status.dump()
print_prompt() print_prompt()
l = sys.stdin.readline() line = read_line(sys.stdin, timeout=3*60.0, timeout_func=status.logout)
if not l:
break
line = l.rstrip()
if line: if line:
print_display('\x0cBarcode:\n%20s' % line[:20]) print_display('\x0cBarcode:\n%20s' % line[:20])
handle(line, status) handle(line, status)