Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old June 27th, 2008, 05:29 PM
joamag
Guest
 
Posts: n/a
Default Way to unblock sys.stdin.readline() call

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...

Thanks in advance,
João
  #2  
Old June 27th, 2008, 05:29 PM
=?iso-8859-1?q?C=E9dric_Lucantis?=
Guest
 
Posts: n/a
Default Re: Way to unblock sys.stdin.readline() call

Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit*:
Quote:
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
  #3  
Old June 27th, 2008, 05:29 PM
joamag
Guest
 
Posts: n/a
Default Re: Way to unblock sys.stdin.readline() call

On Jun 21, 4:46*pm, Cédric Lucantis <o...@no-log.orgwrote:
Quote:
Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit*:
>
Quote:
HI,
>
Quote:
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
  #4  
Old June 27th, 2008, 05:29 PM
Terry Reedy
Guest
 
Posts: n/a
Default Re: Way to unblock sys.stdin.readline() call



joamag wrote:
Quote:
Is there any possible way to unblock the sys.stdin.readline() call
from a different thread.
If you want the thread to do something 'else' when no input is
available, would this work? Put readline in a thread that puts lines in
a q=queue.Quese(). Then
try:
l=q.ge_nowait
<process l>
except queue.Empty
<whatever without l>

  #5  
Old June 27th, 2008, 05:29 PM
joamag
Guest
 
Posts: n/a
Default Re: Way to unblock sys.stdin.readline() call

On Jun 21, 11:34*pm, Terry Reedy <tjre...@udel.eduwrote:
Quote:
joamag wrote:
Quote:
Is there any possible way to unblock the sys.stdin.readline() call
from a different thread.
>
If you want the thread to do something 'else' when no input is
available, would this work? *Put readline in a thread that puts lines in
a q=queue.Quese(). *Then
try:
* * *l=q.ge_nowait
* * *<process l>
except queue.Empty
* * *<whatever without l>
Yes, that would work but still I would have a thread that would block
(the one with the readline call).
The problem with that solution is that if I try to exit the
application, while the thread is waiting in the readline call, that
thread would be blocking the exit of the application.
That behavior occurs even if the thread is configured in daemon mode.
Do you think it’s possible to solve the readline blocking problem in
any other way ?
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles