Skip to content

Commit

Permalink
Merge branch 'jdaw/disable-progress-bar-redirected' into 'master'
Browse files Browse the repository at this point in the history
Disable progress bar for resume if stderr != tty

See merge request machine-learning/dorado!738
  • Loading branch information
tijyojwad committed Nov 29, 2023
2 parents e0151fb + 7c05aba commit 0a07110
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dorado/read_pipeline/ResumeLoaderNode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ResumeLoaderNode.h"

#include "HtsReader.h"
#include "utils/tty_utils.h"

#include <htslib/sam.h>
#include <indicators/indeterminate_progress_bar.hpp>
Expand All @@ -27,6 +28,11 @@ void ResumeLoaderNode::copy_completed_reads() {
indicators::option::PostfixText{"Resuming from file"},
indicators::option::Stream{std::cerr}};

// Only log using progress bar if stderr is tty. If stderr is being
// routed to a file, the IndeterminateProgressBar just spams the file
// with dots.
bool is_safe_to_log = utils::is_fd_tty(stderr);

// Turn off logging for warnings.
auto initial_hts_log_level = hts_get_log_level();
hts_set_log_level(HTS_LOG_OFF);
Expand All @@ -39,7 +45,7 @@ void ResumeLoaderNode::copy_completed_reads() {
std::string read_id = bam_get_qname(reader.record);
m_processed_read_ids.insert(read_id);
m_sink.push_message(BamPtr(bam_dup1(reader.record.get())));
if (m_processed_read_ids.size() % 100 == 0) {
if (is_safe_to_log && m_processed_read_ids.size() % 100 == 0) {
bar.tick();
}
}
Expand Down

0 comments on commit 0a07110

Please sign in to comment.