Skip to content

Commit

Permalink
Fix C++ version of MonitorStage output issue caused by out of order…
Browse files Browse the repository at this point in the history
… function calls (#2140)

<img width="532" alt="image" src="https://github.com/user-attachments/assets/39f491c6-4551-44a1-94a9-d3f420cf78e1" />

- [#2121](#2121) ensures the cursor is reset to the last line of output after shutdown by adding `ProgressBarContextManager::mark_pbar_as_completed()`. 
- When executing some of the pipelines, race conditions may cause calling `ProgressBarContextManager::display_all()` after `ProgressBarContextManager::mark_pbar_as_completed()`, which intermittently causes the log display issue above - which should has been fixed by this PR.

Closes #2119 

## By Submitting this PR I confirm:
- I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md).
- When the PR is ready for review, new or existing tests cover these changes.
- When the PR is ready for review, the documentation is up to date with these changes.

Authors:
  - Yuchen Zhang (https://github.com/yczhang-nv)
  - David Gardner (https://github.com/dagardner-nv)

Approvers:
  - David Gardner (https://github.com/dagardner-nv)
  - Will Killian (https://github.com/willkill07)

URL: #2140
  • Loading branch information
yczhang-nv authored Jan 28, 2025
1 parent 6e2d715 commit 199eae2
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class ProgressBarContextManager
{
std::lock_guard<std::mutex> lock(m_mutex);

// To avoid display_all() being executed after calling mark_pbar_as_completed() in some race conditions
if (m_is_completed)
{
return;
}

// A bit of hack here to make the font settings work. Indicators enables the font options only if the bars are
// output to standard streams (see is_colorized() in <indicators/termcolor.hpp>), but since we are still using
// the ostream (m_stdout_os) that is connected to the console terminal, the font options should be enabled.
Expand All @@ -114,11 +120,11 @@ class ProgressBarContextManager
{
pbar->print_progress(true);
m_stdout_os << termcolor::reset; // The font option only works for the current bar
m_stdout_os << "\n";
m_stdout_os << std::endl;
}

// After each round of display, move cursor up ("\033[A") to the beginning of the first bar
m_stdout_os << "\033[" << m_progress_bars.size() << "A";
m_stdout_os << "\033[" << m_progress_bars.size() << "A" << std::flush;
}

void mark_pbar_as_completed(size_t bar_id)
Expand Down

0 comments on commit 199eae2

Please sign in to comment.