473,385 Members | 1,720 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,385 software developers and data experts.

FIFO problems

Hi!

I want to write a "client-server-application" (only running on the same
machine) or actually I've already begun with and have problems with the
interprocess communication. The server, when started, opens a FIFO and
opens it with open(infifo, 'r'). Then I check the content of the file
with

while 1:
line = serverIn.readline()[:-1]
if line == "bla":
do this
else:
print line

So at the beginning everything works fine. I can start the client prog
and they will talk and understand to each other. The same if I connect
with three or more clients simultaneously (?). If one of these clients
exists, no problem. But when the last process exists and closes the
FIFO-file which was opened by os.open(infifo, os.O_WRONLY), the server
begins to print an empty string everytime it goes through the loop,
means it won't wait for a complete line to appear before continuing.
Why?
Then I modified the thing above to:

while 1:
line = serverIn.readline()[:-1]
if line == "bla":
do this
elif line == "":
open(infifo, 'r')
print "help!!!"
else:
print line

So in contrast to what I thought, there was not a bunch of "help!!!"
lines printed, but nothing. When I tried then to connect again, there
was a single "help!!!" and then the correct message for the client
having connected.

So, anyone any idea how I can fix this. I just want the server to
continue line-by-line-reading...

Bye
Tobias
Jul 18 '05 #1
7 3120
Hi!

Sorry, big mistake!!

Tobias Pfeiffer <Bo**************@web.de> wrote in
news:bj************@ID-162581.news.uni-berlin.de:
these clients exists, no problem. But when the last process exists


EXITS, not exists...

Bye
Tobias
Jul 18 '05 #2
The most generic method of doing interprocess communication (with
process on the same or different machine) is to use sockets. See
Python's socket module. There are lots of other ways -- pipes (see
the os.popen family) and shared memory, but you'll be able to find
many examples and much documentation for sockets. Reading and writing
straight files (if that is really what you are doing) is probably not
going to work well.

Gary Herron
On Wednesday 10 September 2003 10:23 pm, Tobias Pfeiffer wrote:
Hi!

I want to write a "client-server-application" (only running on the same
machine) or actually I've already begun with and have problems with the
interprocess communication. The server, when started, opens a FIFO and
opens it with open(infifo, 'r'). Then I check the content of the file
with

while 1:
line = serverIn.readline()[:-1]
if line == "bla":
do this
else:
print line

So at the beginning everything works fine. I can start the client prog
and they will talk and understand to each other. The same if I connect
with three or more clients simultaneously (?). If one of these clients
exists, no problem. But when the last process exists and closes the
FIFO-file which was opened by os.open(infifo, os.O_WRONLY), the server
begins to print an empty string everytime it goes through the loop,
means it won't wait for a complete line to appear before continuing.
Why?
Then I modified the thing above to:

while 1:
line = serverIn.readline()[:-1]
if line == "bla":
do this
elif line == "":
open(infifo, 'r')
print "help!!!"
else:
print line

So in contrast to what I thought, there was not a bunch of "help!!!"
lines printed, but nothing. When I tried then to connect again, there
was a single "help!!!" and then the correct message for the client
having connected.

So, anyone any idea how I can fix this. I just want the server to
continue line-by-line-reading...

Bye
Tobias


Jul 18 '05 #3
Quoth Tobias Pfeiffer <Bo**************@web.de>:
....
| So at the beginning everything works fine. I can start the client prog
| and they will talk and understand to each other. The same if I connect
| with three or more clients simultaneously (?). If one of these clients
| exits, no problem. But when the last process exists and closes the
| FIFO-file which was opened by os.open(infifo, os.O_WRONLY), the server
| begins to print an empty string everytime it goes through the loop,
| means it won't wait for a complete line to appear before continuing.
| Why?

It's at end of file. That's what happens when the write end of
a pipe closes, and there's no data left: subsequent reads return
end of file, which in Python is an empty string.

You may close it and open it again at this point.

Donn Cave, do**@drizzle.com
Jul 18 '05 #4
"Tobias Pfeiffer" <Bo**************@web.de> wrote in message
news:bj************@ID-162581.news.uni-berlin.de...
Hi!

I want to write a "client-server-application" (only running on the same
machine) or actually I've already begun with and have problems with the
interprocess communication. The server, when started, opens a FIFO and
opens it with open(infifo, 'r'). Then I check the content of the file
with

while 1:
line = serverIn.readline()[:-1]
if line == "bla":
do this
else:
print line


The problem here is that you aren't testing correctly for and end-of-file
condition.

The slice notation you use to "remove the line terminator" unfortunately
gives the same result for an empty line (one containing only a line
terminator) and end-of-file (which returns a line containing no characters
at all).

There are various ways around this. Since you are talking interactive
multi-process stuff here it's probably safest to do somehting like the
following (untested) code:

while 1:
line = serverIn.readline()
if not line:
break
del line[:-1]
if line == "bla":
do something incredibly interesting
else:
print line

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/

Jul 18 '05 #5
"Steve Holden" <sh*****@holdenweb.com> wrote in
news:tJ*************@news2.central.cox.net:
There are various ways around this. Since you are talking interactive
multi-process stuff here it's probably safest to do somehting like the
following (untested) code:

while 1:
line = serverIn.readline()
if not line:
break
del line[:-1]
if line == "bla":
do something incredibly interesting
else:
print line


Untested is right. Your 'del' statement is a little bit too destructive, or
at least it would be if strings were mutable.

Here's my (equally untested) alternative:

for line in serverIn:
line = line[:-1]
if line == "bla":
do something incredibly interesting
else:
print line

--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #6
"Duncan Booth" <du****@NOSPAMrcp.co.uk> wrote in message
news:Xn*************************@127.0.0.1...
"Steve Holden" <sh*****@holdenweb.com> wrote in
news:tJ*************@news2.central.cox.net:
There are various ways around this. Since you are talking interactive
multi-process stuff here it's probably safest to do somehting like the
following (untested) code:

while 1:
line = serverIn.readline()
if not line:
break
del line[:-1]
if line == "bla":
do something incredibly interesting
else:
print line
Untested is right. Your 'del' statement is a little bit too destructive,

or at least it would be if strings were mutable.
:-) Well, I can only remind myself that "the person who never made a mistake
never made anything".
Here's my (equally untested) alternative:

for line in serverIn:
line = line[:-1]
if line == "bla":
do something incredibly interesting
else:
print line


Unfortunately this doesn't include the end-of-file test that caused me to
write my original incorrect code. If it did, however, I'm sure it would work
;-)

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/

Jul 18 '05 #7
Hi!

"Steve Holden" <sh*****@holdenweb.com> wrote in
news:tJ*************@news2.central.cox.net:
while 1:
line = serverIn.readline()[:-1]
if line == "bla":
do this
else:
print line

The problem here is that you aren't testing correctly for and
end-of-file condition.


So the end-of-file-thingy also ends a line for the readline-command, I
suppose? OK, would make sense for normal file read-processes... *grin*
The slice notation you use to "remove the line terminator"
unfortunately gives the same result for an empty line (one
containing only a line terminator) and end-of-file (which returns a
line containing no characters at all).

There are various ways around this. Since you are talking
interactive multi-process stuff here it's probably safest to do
somehting like the following (untested) code:

while 1:
line = serverIn.readline()
if not line:
break
as changed:
line = line[:-1]
if line == "bla":
do something incredibly interesting
else:
print line


In which case will the "if not line" condition be true? When there is
an end-of-file? But I just don't want it to break, I want it to
continue and wait for a somewhat useful line, e.g. if another client
connects.

Bye and thanks for your help
Tobias
Jul 18 '05 #8

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

Similar topics

4
by: Luca | last post by:
I have the need of a container of integers showing both the characteristics of an associative container (all integer elements different from each other) and the FIFO behaviour. Do you know if...
2
by: worli | last post by:
Hi All, I have a strange requirement. I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc.... ( each input number range from 1 to 10 ). lets take a simple case where all inputs will...
2
by: Michele Moccia | last post by:
How can I implement a "time critical" fifo in c++ ? I just have to manage sequences of raw bytes, no user defined types. An std::queue<unsigned char> or std::deque<unsigned char> seems to be slow....
8
by: Jack | last post by:
I want to implement a fixed-size FIFO queue for characters. I only want to use array not linked list. For example, const int N = 10; char c_array; The question is when the queue is full,...
5
by: Dinsdale | last post by:
I have an application that recieves text data via external input (i.e. serial) and displays it on the screen (we use carraige return as a delimiter). At this point I use a regular old text box and...
1
by: mai | last post by:
Hi everyone, i'm trying to exhibit FIFO anomaly(page replacement algorithm),, I searched over 2000 random strings but i couldnt find any anomaly,, am i I doing it right?,, Please help,,,The...
2
by: Spoon | last post by:
Hello, I'm wondering whether the STL defines a data structure with the following features: o provides push_front() and pop_back() (like std::list) to implement a FIFO buffer. o allows fast...
5
by: doxtor | last post by:
Hi all..I'm a little bit confuse with this problem. I have 3 tables, stock_in, stock_level, and stock_out. stock_in used for save the data product when there's new purchase. stock_out used for...
40
by: sazd1 | last post by:
Hi Student2 I am working on similar kind of thing for stock calculation but could not find any solution to my problem even after putting my problem to different forums. I saw your post that you...
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.