"gsxg" <[EMAIL PROTECTED]> wrote:
> I am new to python, and have written a simple program to read a port
> via telnet. I would like it to run until any key is pressed. Of
> course I wouldn't mind requiring a specific keystroke in the future,
> but I would think this is simpler for now.
>
> I have used kbhit() and getch() many times in C, but I can't find
> anything similar in Python. I am using Linux also, so the msvcrt
> code isn't an option. I have tried sys.stdin.read(), but that hangs
> UNTIL a key is pressed.
Unblock the stdin using the fcntl module. Then you get an IOError
if there is nothing.
def unblock(f):
"""Given file f , sets it unblock flag to true"""
fcntl.fcntl(f.fileno(),fcntl.F_SETFL,os.O_NONBLOCK)
f is the file object you get from the open...
hth - Hendrik
--
http://mail.python.org/mailman/listinfo/python-list