We have an application that invokes a Python interpreter from within a C++ code. The C++ code is parallelized with mpi. The interpreter is used to run Python scripts (these may involve message passing via mpi4py or not).  Here's the problem: When we run the code as a serial code, if the Python scripts contains an error, on stderr we get the message that the interpreter generates with the usual diagnostic information (line where error occurs, type of error,...). If, however, we run the code in parallel over multiple cores, we do not get any diagnostic info from the interpreter. On the C++ side, we know that an error occurred in the script, but that is all. Of course, this makes debug much harder, since some of the errors may only occurs when running in parallel. So my question is how to redirect error messages from the interpreter to a file, or other ideas to deal with this situation.
The problem had to do with how we exit the code after an error on the Python side occurred. 
Originally, we used MPI_Abort(). Switching to std::exit(0) solves the issue. 
Now, when a script generates an error, the Python interpreter messages are correctly displayed (from every process!).
How to deal with python interpreter run-time errors when running python within an mpi code