Skip to content

Instantly share code, notes, and snippets.

@zagfai
Created September 25, 2013 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zagfai/6695647 to your computer and use it in GitHub Desktop.
Save zagfai/6695647 to your computer and use it in GitHub Desktop.
python non blocking input
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" python non blocking input
"""
__author__ = 'Zagfai'
__version__= '2013-09-13'
import sys
import select
from time import sleep
import termios
import tty
old_settings = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
while True:
sleep(.001)
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
c = sys.stdin.read(1)
if c == '\x1b': break
sys.stdout.write(c)
sys.stdout.flush()
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
print raw_input('123:')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment