#!/usr/bin/env python2
from sys import stdin
from select import select
while 1:
(rr, wr, er) = select([stdin], [], [])
for fd in rr:
print fd
program block in the first select(), after I type something and "enter
", it never block in select() again,why? 5 2206
Dio wrote: from sys import stdin from select import select
while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd
program block in the first select(), after I type something and "enter ", it never block in select() again,why?
if there's data waiting to be read from the stream, select() will tell
you so every time you ask.
</F>
Dio wrote: while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd program block in the first select(), after I type something and "enter ", it never block in select() again,why?
select blocks until there is some data to read from stdin, but it does
not *clear* the data. so once you enter data, select will not block
until you read the data. once you're done reading the available data,
you can again use select to block until more data is available.
Regards
Sreeram
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEoM2Ergn 0plK5qqURAm0GAK CxtfwmayK1xmn8o Hq6yi5z4my2hwCg kkta
67h4Y9lUR9RCC6r QFtrRGgU=
=zaqF
-----END PGP SIGNATURE-----
Dio wrote: #!/usr/bin/env python2
from sys import stdin from select import select
while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd
program block in the first select(), after I type something and "enter ", it never block in select() again,why?
Because select blocks until there is something to read on stdin, and as
long as there is something to be read on stdin, it will not block. Since
your program never reads in the data on stdin, your "enter\n" just sits
there waiting to be read, and select always inform you of that fact by
returning stdin in the rr list.
If you want select to start blocking again, you must read all bytes from
stdin whenever select says there are bytes to be read.
Gary Herron
K.S.Sreeram 写道: Dio wrote: while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd
program block in the first select(), after I type something and "enter ", it never block in select() again,why?
select blocks until there is some data to read from stdin, but it does not *clear* the data. so once you enter data, select will not block until you read the data. once you're done reading the available data, you can again use select to block until more data is available.
Regards Sreeram
Thanks a lot!I use stdin.readline( ) after select and it's ok :)
In article <ma************ *************** ************@py thon.org>,
Gary Herron <gh*****@island training.com> wrote: If you want select to start blocking again, you must read all bytes from stdin whenever select says there are bytes to be read.
To add to this, it is a good idea to read the select_tut(2) man page,
particularly the "SELECT LAW" section. There's a lot of dos and don'ts
there on how to avoid common bugs. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: prabu |
last post by:
Hello all,
I am new to Python,And this is my first post.I have installed "Fsh",an Opensource Product ,very similar to SSH on
my HP-UX B.11.22 U ia64(IPF).It has Python dependency.The problem is that,when I execute Fsh at commanline
following error occurs,
# fsh
Traceback (most recent call last):
File "/usr/bin/fsh", line 6, in ?
import fsh
File "/opt/iexpress/fsh/share/fsh/fsh.py", line 22, in ?
import select
|
by: D. Shifflett |
last post by:
Hi all,
I am having trouble with a program that ran fine on
Python 2.0 (#0, Mar 1 2001, 01:47:55)
on linux2
but will not work on
Python 2.3.2 (#1, Oct 8 2003, 17:33:47)
on linux2
|
by: John Fabiani |
last post by:
Hi,
I'm a newbie and I'm attempting to learn howto create a select statement.
When I use
>>> string1='18 Tadlock Place'
>>> cursor.execute("SELECT * FROM mytest where address = %s",string1)
All works as expected. But
>>> numb=10
>>> cursor.execute("SELECT * FROM mytest where clientID = %d",numb)
Traceback (innermost last):
File "<stdin>", line 1, in ?
|
by: Brad Murdoch |
last post by:
im trying to run the select.selct() on a unix pipe, my expectation is
that it will block untill there is something there to read, then
continue. It seems to do this untill the pipe is written to once, then i
get a busy while loop.
shouldnt this stop each time, to wait for something to be written to
the pipe. obviously im a novice when it comes to python programming,
what am i missing here.
cheers..
|
by: Magnus Lycka |
last post by:
I'm trying to read standard out in a process started with popen2
in a non-blocking way. (Other good ways of doing this than the
one I tried are appreciated.)
I've tried to dumb down my code to see what happens, and
socket.poll seems to behave very strangely. I've tried to
use the .poll method for the poll object with and without
a timeout, but in either case, the output randomly switches
between on of the versions below. It runs fast,...
| |
by: grunar |
last post by:
After some thought on what I need in a Python ORM (multiple primary
keys, complex joins, case statements etc.), and after having built
these libraries for other un-named languages, I decided to start at the
bottom. What seems to plague many ORM systems is the syntactic
confusion and string-manipulation required to build the SQL Statements.
If you want to do a Left Outer Join, support nested functions, and a
nested conditional clause, you'd...
|
by: ZoombyWoof |
last post by:
Hi. I have ran into a weird thing I just can't find any solution for. I
have googled and searched but no luck.
The problem is that when I select TIME values from MySQL from python, I
get wrong results when the TIME values are negative.
From mysql program:
mysqlselect id,flex from Users where id=2;
+----+----------+
| id | flex |
|
by: Ron Garret |
last post by:
Here's my code. It's a teeny weeny little HTTP server. (I'm not really
trying to reinvent the wheel here. What I'm really doing is writing a
dispatching proxy server, but this is the shortest way to illustrate the
problem I'm having):
from SocketServer import *
from socket import *
from select import select
class myHandler(StreamRequestHandler):
|
by: Derek Martin |
last post by:
Hi kids!
I've got some code that uses select.select() to capture all the output
of a subprocess (both stdout and stderr, see below). This code works
as expected on a variety of Fedora systems running Python 2.4.0, but
on a Debian Sarge system running Python 2.2.1 it's a no-go. I'm
thinking this is a bug in that particular version of Python, but I'd
like to have confirmation if anyone can provide it.
The behavior I see is this: the...
|
by: Nikhil |
last post by:
I am using the MySQLdb python module. I have a table named 'testing'
with few columns, under the 'test' database, what is hosted on a remote
mysql server.
I want to run the following query to get a comma-seperated information
from the table
LOCK TABLES foo READ;
SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt'
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |