Python 2.7: read from stdin without prompting -
i'm trying make arduino yun alarm system. needs make requests web server update stats. needs monitor button , motion sensor. linux side running python script make web requests. need have arduino send status python script. in python script, need read arduino side. can print raw_input()
, want read if there available, don't want block if nothing available. example:
import time while 1: print "test" time.sleep(3) print raw_input() time.sleep(3)
if run it, want print:
test (6 seconds later) test
instead of
test (infinite wait until type in)
i've tried threads, they're little hard use.
simple solution waits single line of data. uses file-like sys.stdin object.
import sys while true: print "pre" sys.stdin.readline() print "post"
Comments
Post a Comment