You can use select () in sys.stdin in conjunction with a timeout. Roughly speaking, your main loop will look like this (untested):
while True: r,w,e = select.select([sys.stdin], [], [], 600) if sys.stdin in r: # data available on sys.stdin if sys.stdin.read() == 'q': break # do gmail stuff
To be able to read one character from stdin, you will need to put stdin in unbuffered mode. An alternative is described here . If you want everything to be simple, just ask the user to press Enter after "q"
The -u flag I mentioned earlier will not work: it can put pyton in unbuffered mode, but not your terminal.
Alternatively, ncursus may help. I'm just hinting, I don't have much experience with this; if I want a fantastic user interface, I would use TkInter.
source share