473,725 Members | 2,242 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 3574
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
3374
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
53310
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
2399
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
5198
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
2783
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
3260
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
11170
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
1431
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
8884
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8749
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9400
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9252
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...
0
8084
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...
0
4508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3217
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
2631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2154
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.