How to turn console echo back on after tty.setcbreak()
<p>I am using this command to disable echo and fetch user input using <code>sys.stdin.read(1)</code></p>

<pre><code>tty.setcbreak(sys.stdin.fileno())
</code></pre>

<p>However during the course of my program I need to again enable and disable console echo. I tried </p>

<pre><code>fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
termios.tcsetattr(fd, termios.TCSADRAIN, old)
</code></pre>

<p>But that aint working. How can I elegantly enable echo?</p>

<p>ps: I am using code from <a href="http://stackoverflow.com/a/2409034/842837">Python nonblocking console input</a> by mizipzor</p>

<p><strong>Update:</strong> Heres the code:</p>

<pre><code>import sys
import select
import tty
import termios
import time

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False

def calc_time(traw):
    tfactor = {
    's':    1,
    'm':    60,
    'h':    3600,
    }
    if is_number(g[:-1]):
        return float(g[:-1]) * tfactor.get(g[-1])
    else:
        return None   
def isData():
    return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])

old_settings = termios.tcgetattr(sys.stdin)
try:
    tty.setcbreak(sys.stdin.fileno())
    i = 0
    while 1:
        print i
        i += 1
        time.sleep(.1)
        if isData():
            c = sys.stdin.read(1)
            if c:
                if c == 'p':
                    print """Paused. Use the Following commands now:
Hit 'n' to skip and continue with next link.
Hit '5s' or '3m' or '2h' to wait for 5 secs, 3 mins or 3 hours
Hit Enter to continue from here itself.
Hit Escape to quit this program"""
                    #expect these lines to enable echo back again
                    fd = sys.stdin.fileno()
                    old = termios.tcgetattr(fd)
                    old[3] = old[3] &amp; termios.ECHO
                    termios.tcsetattr(fd, termios.TCSADRAIN, old)

                    g = raw_input("(ENABLE ECHO HERE):")

                    if g == '\x1b':
                        print "Escaping..."
                        break
                    if g == 'n':
                        #log error
                        continue
                    elif g[-1] in ['s','m','h']:
                        tval = calc_time(g)
                        if tval is not None:
                            print "Waiting for %s seconds."%(tval)
                            time.sleep(tval)
                    continue

finally:
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
</code></pre>
