Skip to content

Instantly share code, notes, and snippets.

@davstott
Created March 5, 2013 00:23
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save davstott/5086945 to your computer and use it in GitHub Desktop.
Linux python asynchronous input from stdin using select()
#Replacing
thisChar = sys.stdin.read(1)
#With
import select
try:
if select.select([sys.stdin,], [], [], 0)[0]:
thisChar = sys.stdin.read(1)
else:
if (debug):
print "nothing to read"
except IOError:
#nothing to read. should really have checked first
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment