Way to unblock sys.stdin.readline() call

Jean-Paul Calderone exarkun at divmod.com
Sun Jun 22 00:18:45 CEST 2008

On Sat, 21 Jun 2008 12:35:02 -0700 (PDT), joamag <joamag at gmail.com> wrote:
>On Jun 21, 4:46 pm, Cédric Lucantis <o... at no-log.org> wrote:
>> Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit :
>> > HI,
>> > Is there any possible way to unblock the sys.stdin.readline() call
>> > from a different thread.
>> > Something like sys.stdin.write() but that would actually work ...
>> > something to put characters in the stdin...
>> Do you mean setting stdin in non-blocking mode ? On unix you can do it with
>> the fcntl module (you'll find more infos in the libc docs) :
>> fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK)
>> and catch IOErrors with errno = EAGAIN. But I don't know how to do it in a
>> portable way, suggestions welcome :)
>> --
>> Cédric Lucantis
>Thanks for the advice that's a way of solving my problem, but I really
>need a portable way of doing it...
>The application I’m build is meant to be run in more platforms than
>Unix ... so I really need a portable way of doing that or something
>else that unblocks the read call in the stdin

Twisted supports asynchronous handling of stdin on both POSIX and Windows.

See stdiodemo.py and stdin.py under the Miscellaenous section at


More information about the Python-list mailing list