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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -