+def read_command(io_db):
+ """Return next newline-delimited command from server in file.
+
+ Keep building return string until a newline is encountered. Pause between
+ unsuccessful reads, and after too much waiting, run server_test().
+ """
+ wait_on_fail = 1
+ max_wait = 5
+ now = time.time()
+ command = ""
+ while 1:
+ add = io_db["file_in"].readline()
+ if len(add) > 0:
+ command = command + add
+ if len(command) > 0 and "\n" == command[-1]:
+ command = command[:-1]
+ break
+ else:
+ time.sleep(wait_on_fail)
+ if now + max_wait < time.time():
+ server_test(io_db)
+ now = time.time()
+ return command