tags:

views:

179

answers:

3

I want to have an application writing out information at the same time that a monitor is reading it. The application is "embedded" (and on Win32 XP) and so has restricted memory and I/O functionality.

The simplest way I can think to do this is by writing the data to a buffer file from the application, and then read the same file using the monitor application. The writer application is C++, and the reader is currently Python on Win32 XP.

Are there libraries to do this? Has anyone seen examples of this?

I don't want to have to use a database as I don't want to link to a database library in the applcation. I.e. don't have space and may not be supported on the embedded platform.

Another way to do this is over a network connection, but I figure files are the simplest solution.

+4  A: 

Most systems has several solutions for what you want to do, such as pipes and unix sockets. These are intended for this, unlike regular files. There are however programs that does this on regular files, and I think the clearest example of this is the unix-utility tail, which can "follow" a file.

Take a look at
http://msdn.microsoft.com/en-us/library/aa365590(VS.85).aspx

Python has a good wrapper library for win32, so anything you see there can probably be access from python.

Emil H
Thanks Emil. Do you happen to know how the speed of pipes compares with sockets?
Nick
I have a faint memory of reading that pipes are substantially faster, but I wouldn't bet on it. It does seem logical, though. Good luck with your project! :)
Emil H
Pipes are a shared in-memory buffer. Sockets connected via localhost are also shared in-memory buffers. Pipes have slightly less overhead.
S.Lott
+1  A: 

What you're talking about is called "Interprocess Communication". There are lots of ways of doing this.

Using Unix pipes.

http://www.python.org/doc/2.5.2/lib/module-pipes.html

Using sockets.

http://www.python.org/doc/2.5.2/lib/module-socket.html

Using queues.

http://www.python.org/doc/2.5.2/lib/module-Queue.html

Any of these is better than file I/O.

S.Lott
Queue does not work between different processes.
bialix
@bialix: Thanks. The queue -- by itself -- isn't a solution. But I think an excellent solution can be built using sockets, queues and wsgi_ref.
S.Lott
+2  A: 

You can use memory-mapped files, standard Python module called mmap.

bialix