read stdin NON-BLOCKING

Boyd Roberts boyd at insultant.net
Wed Sep 26 06:11:52 EDT 2001


"Martin von Loewis" <loewis at informatik.hu-berlin.de> a écrit dans le message news: j4u1xra1zk.fsf at informatik.hu-berlin.de...
> When you say 'blocking', do you mean 'line-buffered'? Are you using a
> Unix system?

it depends what you're trying to read.

> os.system("stty raw")

that is a ghastly idea.

> I don't know which specific parameters to use, though - if you find out,
> could you please post them?

it's a termios thing.  turn off ICANON and set VMIN and VTIME appropriatly
(both to zero iirc).

i don't have the stomach to RTFM, but i do have this example (of working
code) that deals with character echo:

# yes it's part of a bundle [shar]
echo tty.c
sed 's/.//' >tty.c <<'//GO.SYSIN DD tty.c'
-/*
- * @(#)tty.c	1.1
- *
- * Horrible system dependent tty routines.
- */
-
-#include	"mace.h"
-#include	<termios.h>
-
-/*
- * Is echo on?
- */
-int
-ttyechoing(int fd)
-{
-	struct termios	t;
-
-	if (tcgetattr(fd, &t) == SYSERROR)
-		return SYSERROR;
-
-	return (t.c_lflag & ECHO) != 0;
-}
-
-/*
- * Turn echo off/on?
- */
-int
-ttyecho(int fd, int on)
-{
-	struct termios	t;
-
-	if (tcgetattr(fd, &t) == SYSERROR)
-		return SYSERROR;
-
-	if (on)
-		t.c_lflag |= ECHO;
-	else
-		t.c_lflag &= ~ECHO;
-
-	return tcsetattr(fd, TCSADRAIN, &t);
-}
//GO.SYSIN DD tty.c






More information about the Python-list mailing list