473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 5992
In article <ma**************************************@python.o rg>,
Brad Murdoch <br**@it.alliedpress.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.fifo', os.O_RDONLY)
...
while 1:
...
data = os.read(fifd, 8192)

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

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

Similar topics

0
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...
1
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,...
0
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...
5
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...
3
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...
7
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...
2
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...
16
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...
0
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.