Sharing information between two different programs

I have a program written in C++, which evolves a neural network and, whenever a new solution is found, saves it to a binary file using an ofstream. I would like to visualise the result in real time, but have found the available c++ tools for drawing to be way too complex for what I need, plus I don't really have the time nor desire to learn the tools for this single use (I don't plan to become a graphics/forms guy).

I already know python quite well so I was thinking of simply having a python script check the file periodically and look for changes, and then display them.

My concern is that it will be difficult to communicate to the other program whether the file is in use. So from a c++ perspective, how do I make my program wait until the file is closed? And, is it possible to race conditions to occur?

As the file saving only occurs several times a minute, and the files shouldn't be larger than a few million bytes, I'm not particularly concerned about performance.
Last edited on
After you close the file, does the program terminate?
No. Both programs will continue running. The C++ program will continue to find another solution and the python script will keep checking for updates to the file.
The simplest solution I can think of is to write every solution to a different file. After the solution file is closed by the solution generator, append its name to a filelist file.

The python script should monitor the filelist file for changes, once a filename is found by the python program in the filelist file, then we know it contains a solution, and has been closed by the solution generator.

We have a similar problem and use gearman, but it's probably overkill for you as we require two way communication.

Topic archived. No new replies allowed.