Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > named pipe and Linux

Reply
Thread Tools

named pipe and Linux

 
 
akineko
Guest
Posts: n/a
 
      04-07-2009
Hello everyone,

I'm trying to use named pipes to fuse a Python program and a C
program.
One side creates pipes using os.mkfifo() and both sides use the same
named pipes (one side reads, another side writes). The read side uses
select.select() to wait for incoming messages and read the message
when select.select() says it is ready.

The length of the message is unknown to the read side.
I cannot use file.read() because it will block waiting for an EOF.
I cannot use file.readline() because how many lines have arrived is
unknown.
So, I needed to use os.read() with the exact number of characters to
read.

Under Solaris environment, os.fstat() provides the exact size of the
message that has arrived.
Thus, two processes can communicate each other through the named pipes
without blocking.

However, the above scheme didn't work under Linux.
Linux os.fstat() returns size=0 even the message is pending.
(I think Linux buffers the message in memory while Solaris buffers the
message in a file system)

My question is, how can I make the named pipe scheme work under Linux?
Is there any way to read the message without getting blocked?

I know this is more Linux question than Python question but I believe
many Python programmers are strong Linux programmers.

Any suggestions will be appreciated.

Best regards,
Aki Niimura
 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      04-07-2009
In message <5b5157dd-
ca70-4c6d-8adb->, akineko wrote:

> The length of the message is unknown to the read side.


I think you want a message-based, not a stream-based, IPC mechanism. Look at
the docs on msgctl, msgget, msgop and so on.

 
Reply With Quote
 
 
 
 
bobicanprogram
Guest
Posts: n/a
 
      04-08-2009
On Apr 7, 1:08 pm, akineko <akin...@gmail.com> wrote:
> Hello everyone,
>
> I'm trying to use named pipes to fuse a Python program and a C
> program.
> One side creates pipes using os.mkfifo() and both sides use the same
> named pipes (one side reads, another side writes). The read side uses
> select.select() to wait for incoming messages and read the message
> when select.select() says it is ready.
>
> The length of the message is unknown to the read side.
> I cannot use file.read() because it will block waiting for an EOF.
> I cannot use file.readline() because how many lines have arrived is
> unknown.
> So, I needed to use os.read() with the exact number of characters to
> read.
>
> Under Solaris environment, os.fstat() provides the exact size of the
> message that has arrived.
> Thus, two processes can communicate each other through the named pipes
> without blocking.
>
> However, the above scheme didn't work under Linux.
> Linux os.fstat() returns size=0 even the message is pending.
> (I think Linux buffers the message in memory while Solaris buffers the
> message in a file system)
>
> My question is, how can I make the named pipe scheme work under Linux?
> Is there any way to read the message without getting blocked?
>
> I know this is more Linux question than Python question but I believe
> many Python programmers are strong Linux programmers.
>
> Any suggestions will be appreciated.
>
> Best regards,
> Aki Niimura



The SIMPL open source project (http://www.icanprogram.com/simpl)
provides an ultra lightweight toolkit useful for joining Python
programs to C programs using a Send/Receive/Reply mechanism first
pioneered by QNX. SIMPL uses a fifo synchronized shared memory
scheme for the local message pass. Through the use of generic
surrogate pairs SIMPL processes can be distributed across TCP/IP or
RS232 (think radio modem) networks often times without any changes or
recompiles. Through the use of another type of generic surrogate a
Python module running on a nonLinux OS can communicate transparently
with a module running on a Linux box.

A SIMPL application consists of two or more SIMPL modules
collaborating in this way. SIMPL modules can be written in any
number of languages including Python, C, C++, Tcl/Tk or JAVA. More
importantly SIMPL modules written in different languages can be mixed
in a given SIMPL application.

There is a Sudoku puzzle solver example here:

http://www.icanprogram.com/simplBook...Book.self.html

bob
SIMPL project facilitator
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: named pipe and Linux Cameron Simpson Python 2 04-08-2009 04:13 PM
named pipe and "Text file busy" mikexf@gmail.com Perl Misc 3 11-28-2007 11:17 PM
named pipe problem on linux richard C++ 5 11-02-2004 07:44 PM
[named pipe] i wanna know about validate of pipe handle of client lee, wonsun C++ 1 11-02-2004 04:29 AM
Why does IO::Pipe::END generate an EXCEPT pipe message? lvirden@gmail.com Perl Misc 1 06-02-2004 02:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57