From bc0346eae7b6f84043215fde144c1311e81558b5 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 6 May 2014 14:39:48 +0000 Subject: [PATCH] Avoid deadlocks in cti to ctml conversions on Windows --- src/base/ct2ctml.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/base/ct2ctml.cpp b/src/base/ct2ctml.cpp index 12def26b7..66f50a7d6 100644 --- a/src/base/ct2ctml.cpp +++ b/src/base/ct2ctml.cpp @@ -15,6 +15,10 @@ #include #include +#ifdef _WIN32 +#include +#endif + using namespace Cantera; using namespace std; @@ -95,6 +99,7 @@ std::string ct2ctml_string(const std::string& file) stringstream output_stream, error_stream; std::vector args; args.push_back("-c"); + args.push_back( "from __future__ import print_function\n" "import sys\n" @@ -108,16 +113,20 @@ std::string ct2ctml_string(const std::string& file) python.start(pypath(), args.begin(), args.end()); std::string line; - while (true) { - if (python.out().good()) { - std::getline(python.out(), line); - output_stream << line << std::endl; - } else if (python.err().good()) { - std::getline(python.err(), line); - error_stream << line << std::endl; - } else { - break; - } + + while (python.out().good()) { + std::getline(python.out(), line); + output_stream << line << std::endl; + } + +#ifdef _WIN32 + // Sleeping for 1 ms prevents a (somewhat inexplicable) deadlock while + // reading from the stream. + Sleep(1); +#endif + while (python.err().good()) { + std::getline(python.err(), line); + error_stream << line << std::endl; } python.close(); python_exit_code = python.exit_code();