473,670 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select() on pipe

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

#!/usr/bin/python

import os
import sys
import select

try:
fifo = open('test.fifo ','r')
except Exception, blah:
report = "ERROR 001: " + str(blah)
print report
sys.exit(2)

while 1:
line = False
r,w,x = select.select([fifo],[],[])
if r:
line=fifo.read( )
print line

Jul 19 '05 #1
1 6023
In article <ma************ *************** ***********@pyt hon.org>,
Brad Murdoch <br**@it.allied press.co.nz> wrote:
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.
try:
fifo = open('test.fifo ','r') while 1:
line = False
r,w,x = select.select([fifo],[],[])
if r:
line=fifo.read( )
print line

Well, two things, neither of them really unique to
Python. The immediate problem is the semantics of
pipe I/O, specifically "end of file." For pipes
and other IPC devices, end of file means that the
the other end of the file has been closed, which
your "the pipe is written to" event probably does.
From this point on, read(2) returns 0 bytes, which
means end of file. If you want to go back and do
this again, you need to re-open the pipe.

The second problem will bite you as soon as you get
the first part working: fifo.read() is going to
block until the pipe closes. If you switch to
fifo.readline() , select may start failing to detect
data that readline() buffers. For more reliable
I/O in conjunction with select(), use POSIX I/O:

fifd = os.open('test.f ifo', os.O_RDONLY)
...
while 1:
...
data = os.read(fifd, 8192)

Donn Cave, do**@u.washingt on.edu
Jul 19 '05 #2

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

Similar topics

0
5843
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child
1
27318
by: jenny | last post by:
Hi, I have a java socket program running on AIX 4.3.3.0 platform. It opens a socket and sends data to our customer over a leased fractional T1 line. The line is always connected. However, periodically, I see "java.IO.Exception: There is no process to read data written to a pipe" error message in my log file. Can anybody tell me in what cases this error message could occur? The other strange thing is that our customer would report...
0
583
by: Hans Maurer | last post by:
>Description: We're running our current TTS application with MySQL (on Unix). All database, table and column names are in lower-case. However, we need to access this database with a new application which (for some reason) converts all table and column names in its SELECT statements to uppercase. Since MySQL is case-sensitive on Unix, I added the statement set-variable = lower_case_table_names=1 to /etc/my.cnf. However, statements...
5
17417
by: richard | last post by:
I have a simple test to pass information from a client to a server using named pipe. what I really want is: when I type a line on the client, the server will output the line immediately. but to my surprise, I always have to terminate the client to get the server in action, i.e. prints out what I typed. anything I missed? I am compiling using gcc without any option. thanks, ---RICH
3
17385
by: PC | last post by:
Is it possible to create pipe()s (stdin/stdout) for a child process and forking a shell with execl() and controlling the shell's stdin/stdout from the parent with select()? Heres a little snippet of code. it doesnt actually work.. but it is how I envisioned it:: if((n=accept(s,(struct sockaddr *)&remote,&sz))==-1) {printf("accept\n"); exit(0);} close(0); close(1); close(2); pipe(&i);
7
3700
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in filestream. If ANYONE could offer ANY suggestion as to why this is happening it would be much appreciated. Thanks in advance!
2
1664
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the "pipelines" you can make with command-line programs. So, I wrote a module called iterwrap.py. You can download it from here: http://home.blarg.net/~steveha/iterwrap.tar.gz
16
2740
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on screen appearance of the Select List grows for the first 5 rows then the scroll bar appears if there's more). So far so good. . . The problem is that none of the rows I'm inserting appear on the screen until I have RETURNed from my function; so If...
0
1771
by: Sonbol | last post by:
Hi, I am new to linux programming. I am using c to develop a program that aims to create many children in order to communicate with their parents through pipes I need the parent to wait for all the children to finish processing and write to their parent using the appropriate pipe for each children. I know that I may use the select function for this purpose and I have read a lot about it but I don't know how to use it in my program code...
0
8468
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
8386
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
8660
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...
1
6213
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
5683
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
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
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
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
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.