diff --git a/paddle/fluid/platform/debug_support.cc b/paddle/fluid/platform/debug_support.cc index 77ff721020ee97cb2145b1086d512fa223b3c4cf..a46db932f6d6f35537aaaabee9bf409610981caa 100644 --- a/paddle/fluid/platform/debug_support.cc +++ b/paddle/fluid/platform/debug_support.cc @@ -23,8 +23,10 @@ template <> std::string PythonDebugSupport::Format() const { std::ostringstream sout; sout << "\nPython Callstacks: \n"; - for (auto& line : info) { - sout << line; + if (!info.empty()) { + for (auto &line : info) { + sout << line; + } } return sout.str(); } diff --git a/paddle/fluid/platform/debug_support.h b/paddle/fluid/platform/debug_support.h index 9d1d54cef7615a9a360aaa07cb69c800daf912ea..2c8ee6ed1f9a460eba98f24634a4e4c42c72894b 100644 --- a/paddle/fluid/platform/debug_support.h +++ b/paddle/fluid/platform/debug_support.h @@ -30,8 +30,8 @@ class DebugSupport { public: // Returns the singleton of DebugSupport. static DebugSupport* GetInstance() { - static std::unique_ptr debugSupport_(nullptr); - static std::once_flag init_flag_; + static thread_local std::unique_ptr debugSupport_(nullptr); + static thread_local std::once_flag init_flag_; std::call_once(init_flag_, [&]() { debugSupport_.reset(new DebugSupport()); });