Don't print backtraces from inside Python.

This is done by adding a 'backtrace' boolean parameter to PrefixedOutStream.
This commit is contained in:
Ryan Curtin
2017-09-08 10:04:41 -04:00
parent d8b8ed03bd
commit 7be0c797ad
4 changed files with 23 additions and 3 deletions
@@ -100,6 +100,14 @@ inline void EnableVerbose()
Log::Info.ignoreInput = false;
}
/**
* Disable backtraces.
*/
inline void DisableBacktrace()
{
Log::Fatal.backtrace = false;
}
} // namespace util
} // namespace mlpack
+5 -1
View File
@@ -72,7 +72,8 @@ void PrintPYX(const ProgramDoc& programInfo,
cout << "cimport arma_numpy" << endl;
cout << "from cli cimport CLI" << endl;
cout << "from cli cimport SetParam, SetParamWithInfo" << endl;
cout << "from cli cimport EnableVerbose" << endl;
cout << "from cli cimport EnableVerbose, DisableBacktrace"
<< endl;
cout << "from cli cimport MoveFromPtr, MoveToPtr" << endl;
cout << "from matrix_utils import to_matrix, to_matrix_with_info" << endl;
cout << endl;
@@ -168,6 +169,9 @@ void PrintPYX(const ProgramDoc& programInfo,
<< "returned." << endl;
cout << " \"\"\"" << endl;
// Disable backtraces.
cout << " DisableBacktrace()" << endl;
// Restore the parameters.
cout << " CLI.RestoreSettings(\"" << programInfo.programName << "\")";
+9 -1
View File
@@ -54,13 +54,17 @@ class PrefixedOutStream
* @param ignoreInput If true, the stream will not be printed.
* @param fatal If true, a std::runtime_error exception is thrown after
* printing a newline.
* @param backtrace If true, attempt to print a backtrace (will only be
* done if HAS_BFD_DL is defined).
*/
PrefixedOutStream(std::ostream& destination,
const char* prefix,
bool ignoreInput = false,
bool fatal = false) :
bool fatal = false,
bool backtrace = true) :
destination(destination),
ignoreInput(ignoreInput),
backtrace(backtrace),
prefix(prefix),
// We want the first call to operator<< to prefix the prefix so we set
// carriageReturned to true.
@@ -113,6 +117,10 @@ class PrefixedOutStream
//! Discards input, prints nothing if true.
bool ignoreInput;
//! If true, on a fatal error, a backtrace will be printed if HAS_BFD_DL is
//! defined.
bool backtrace;
private:
/**
* Conducts the base logic required in all the operator << overloads. Mostly
@@ -113,7 +113,7 @@ PrefixedOutStream::BaseLogic(const T& val)
// Print a backtrace, if we can.
#ifdef HAS_BFD_DL
if (fatal && !ignoreInput)
if (fatal && !ignoreInput && backtrace)
{
size_t nl;
size_t pos = 0;