473,836 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Way to unblock sys.stdin.readl ine() call

HI,

Is there any possible way to unblock the sys.stdin.readl ine() 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
Jun 27 '08 #1
4 3582
Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit*:
HI,

Is there any possible way to unblock the sys.stdin.readl ine() 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
Jun 27 '08 #2
On Jun 21, 4:46*pm, Cédric Lucantis <o...@no-log.orgwrote:
Le Saturday 21 June 2008 15:26:53 joamag, vous avez écrit*:
HI,
Is there any possible way to unblock the sys.stdin.readl ine() 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
Jun 27 '08 #3


joamag wrote:
Is there any possible way to unblock the sys.stdin.readl ine() 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>

Jun 27 '08 #4
On Jun 21, 11:34*pm, Terry Reedy <tjre...@udel.e duwrote:
joamag wrote:
Is there any possible way to unblock the sys.stdin.readl ine() 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 ?
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3379
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm just figuring Python out but have become stalled with the following snippit of code: For some reason, the program stalls after the "read line: x" for the last line. The 'done reading cycle map' message is never generated: while 1: line = file.readline() if line == '':
12
53331
by: Mike Maxwell | last post by:
When I invoke readline() in a for loop, why does it return a series of one-char strings, rather than the full line? >>> for sL in sys.stdin.readline(): print sL .... abc a b c
0
2408
by: Brano Zarnovican | last post by:
Hi ! I'd like to init curses and still have working Python interactive command line. I found that you can replace stdin/stdout/stderr like this: #!/usr/bin/python -i import curses import sys
1
5204
by: Kevin | last post by:
In a newsgroup thread from Jan 8, 2003 between Barry Holsinger and the VBDotNet Team, please review this excerpt: "You understood my problem completely. Your sample code provides a really elegant way to inject CrLf into the input stream, which effectively unblocks the ReadLine method. Last night, I had finally got the WriteConsoleInput
6
2792
by: Christian Convey | last post by:
Hello, I've got a program that (ideally) perpetually monitors sys.stdin for lines of text. As soon as a line comes in, my program takes some action. The problem is, it seems like a very large amount of data must accumulate on sys.stdin before even my first invocation of readline() returns. This delay prevents my program from being responsive in the way it must be.
1
3266
by: Benjamin Rutt | last post by:
There has been a problem that has been bugging me for a while for reading input from standard in. Consider the following simple program: #!/usr/bin/env python import sys print 'enter something: ', answer = sys.stdin.readline().strip() print 'you answered {%s}' % (answer) When I run this interactively, the following happens:
1
11202
by: ywzhan | last post by:
Hi, I am new here. When I use sys.stdin.readline() to get input string from user, how can I set a timeout value for this operation? thank you.
0
1435
by: Jean-Paul Calderone | last post by:
On Sat, 21 Jun 2008 12:35:02 -0700 (PDT), joamag <joamag@gmail.comwrote: Twisted supports asynchronous handling of stdin on both POSIX and Windows. See stdiodemo.py and stdin.py under the Miscellaenous section at http://twistedmatrix.com/projects/core/documentation/examples/ Jean-Paul
0
10559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10601
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10260
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9388
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.