mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-23 05:07:54 +00:00
parallel: Use status() for status message instead of directly using STDERR.
This commit is contained in:
parent
445e154250
commit
f1b7ededc7
|
@ -242,6 +242,8 @@ New in this release:
|
|||
|
||||
* GNU Parallel was cited in: Distinguishing cause from effect using observational data: methods and benchmarks http://arxiv-web3.library.cornell.edu/pdf/1412.3773.pdf
|
||||
|
||||
* GNU Parallel was cited in: Bayesian Inference of Protein Structure from Chemical Shift Data https://peerj.com/preprints/692.pdf
|
||||
|
||||
* GNU Parallel: Open Source For You (OSFY) magazine, October 2013 edition http://www.shakthimaan.com/posts/2014/11/27/gnu-parallel/news.html
|
||||
|
||||
* コマンドを並列に実行するGNU parallelがとても便利 http://bicycle1885.hatenablog.com/entry/2014/08/10/143612
|
||||
|
|
53
src/parallel
53
src/parallel
|
@ -1567,6 +1567,8 @@ sub save_stdin_stdout_stderr {
|
|||
}
|
||||
open $Global::original_stderr, ">&", "STDERR" or
|
||||
::die_bug("Can't dup STDERR: $!");
|
||||
open $Global::status_fd, ">&", "STDERR" or
|
||||
::die_bug("Can't dup STDERR: $!");
|
||||
open $Global::original_stdin, "<&", "STDIN" or
|
||||
::die_bug("Can't dup STDIN: $!");
|
||||
}
|
||||
|
@ -1880,7 +1882,7 @@ sub drain_job_queue {
|
|||
# $Global::start_no_new_jobs
|
||||
# Returns: N/A
|
||||
if($opt::progress) {
|
||||
print $Global::original_stderr init_progress();
|
||||
::status(init_progress());
|
||||
}
|
||||
my $last_header="";
|
||||
my $sleep = 0.2;
|
||||
|
@ -1897,11 +1899,10 @@ sub drain_job_queue {
|
|||
if($opt::progress) {
|
||||
my %progress = progress();
|
||||
if($last_header ne $progress{'header'}) {
|
||||
print $Global::original_stderr "\n", $progress{'header'}, "\n";
|
||||
::status("\n", $progress{'header'}, "\n");
|
||||
$last_header = $progress{'header'};
|
||||
}
|
||||
print $Global::original_stderr "\r",$progress{'status'};
|
||||
flush $Global::original_stderr;
|
||||
::status("\r",$progress{'status'});
|
||||
}
|
||||
if($Global::total_running < $Global::max_jobs_running
|
||||
and not $Global::JobQueue->empty()) {
|
||||
|
@ -1935,8 +1936,7 @@ sub drain_job_queue {
|
|||
not $Global::start_no_new_jobs and not $Global::JobQueue->empty());
|
||||
if($opt::progress) {
|
||||
my %progress = progress();
|
||||
print $Global::original_stderr "\r", $progress{'status'}, "\n";
|
||||
flush $Global::original_stderr;
|
||||
::status("\r", $progress{'status'}, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1944,11 +1944,10 @@ sub toggle_progress {
|
|||
# Turn on/off progress view
|
||||
# Uses:
|
||||
# $opt::progress
|
||||
# $Global::original_stderr
|
||||
# Returns: N/A
|
||||
$opt::progress = not $opt::progress;
|
||||
if($opt::progress) {
|
||||
print $Global::original_stderr init_progress();
|
||||
::status(init_progress());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2760,14 +2759,14 @@ sub save_original_signal_handler {
|
|||
sub list_running_jobs {
|
||||
# Returns: N/A
|
||||
for my $v (values %Global::running) {
|
||||
print $Global::original_stderr "$Global::progname: ",$v->replaced(),"\n";
|
||||
::status("$Global::progname: ",$v->replaced(),"\n");
|
||||
}
|
||||
}
|
||||
|
||||
sub start_no_new_jobs {
|
||||
# Returns: N/A
|
||||
$SIG{TERM} = $Global::original_sig{TERM};
|
||||
print $Global::original_stderr
|
||||
::status
|
||||
("$Global::progname: SIGTERM received. No new jobs will be started.\n",
|
||||
"$Global::progname: Waiting for these ", scalar(keys %Global::running),
|
||||
" jobs to finish. Send SIGTERM again to stop now.\n");
|
||||
|
@ -2847,7 +2846,7 @@ sub process_failed_job {
|
|||
$Global::total_failed / $Global::total_started > $opt::halt_on_error)) {
|
||||
# If halt on error == 1 or --halt 10%
|
||||
# we should gracefully exit
|
||||
print $Global::original_stderr
|
||||
::status
|
||||
("$Global::progname: Starting no more jobs. ",
|
||||
"Waiting for ", scalar(keys %Global::running),
|
||||
" jobs to finish. This job failed:\n",
|
||||
|
@ -2856,7 +2855,7 @@ sub process_failed_job {
|
|||
$Global::halt_on_error_exitstatus = $job->exitstatus();
|
||||
} elsif($opt::halt_on_error == 2) {
|
||||
# If halt on error == 2 we should exit immediately
|
||||
print $Global::original_stderr
|
||||
::status
|
||||
("$Global::progname: This job failed:\n",
|
||||
$job->replaced(),"\n");
|
||||
exit ($job->exitstatus());
|
||||
|
@ -2972,7 +2971,7 @@ sub citation_notice {
|
|||
-e $ENV{'HOME'}."/.parallel/will-cite") {
|
||||
# skip
|
||||
} else {
|
||||
print $Global::original_stderr
|
||||
::status
|
||||
("Academic tradition requires you to cite works you base your article on.\n",
|
||||
"When using programs that use GNU Parallel to process data for publication please cite:\n",
|
||||
"\n",
|
||||
|
@ -2984,27 +2983,30 @@ sub citation_notice {
|
|||
"\n",
|
||||
"To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'.\n\n",
|
||||
);
|
||||
flush $Global::original_stderr;
|
||||
}
|
||||
}
|
||||
|
||||
sub status {
|
||||
my @w = @_;
|
||||
my $fh = $Global::status_fd || *STDERR;
|
||||
print $fh @w;
|
||||
flush $fh;
|
||||
}
|
||||
|
||||
sub warning {
|
||||
my @w = @_;
|
||||
my $fh = $Global::original_stderr || *STDERR;
|
||||
my $fh = $Global::status_fd || *STDERR;
|
||||
my $prog = $Global::progname || "parallel";
|
||||
print $fh $prog, ": Warning: ", @w;
|
||||
}
|
||||
|
||||
|
||||
sub error {
|
||||
my @w = @_;
|
||||
my $fh = $Global::original_stderr || *STDERR;
|
||||
my $fh = $Global::status_fd || *STDERR;
|
||||
my $prog = $Global::progname || "parallel";
|
||||
print $fh $prog, ": Error: ", @w;
|
||||
}
|
||||
|
||||
|
||||
sub die_bug {
|
||||
my $bugid = shift;
|
||||
print STDERR
|
||||
|
@ -3445,7 +3447,7 @@ sub my_dump {
|
|||
if ($@) {
|
||||
my $err = "Neither Data::Dump nor Data::Dumper is installed\n".
|
||||
"Not dumping output\n";
|
||||
print $Global::original_stderr $err;
|
||||
::status($err);
|
||||
return $err;
|
||||
} else {
|
||||
return Dumper(@dump_this);
|
||||
|
@ -4008,11 +4010,11 @@ sub compute_max_loadavg {
|
|||
close $in_fh;
|
||||
$load = $self->compute_max_loadavg($opt_load_file);
|
||||
} else {
|
||||
print $Global::original_stderr "Cannot open $loadspec\n";
|
||||
::error("Cannot open $loadspec\n");
|
||||
::wait_and_exit(255);
|
||||
}
|
||||
} else {
|
||||
print $Global::original_stderr "Parsing of --load failed\n";
|
||||
::error("Parsing of --load failed\n");
|
||||
::die_usage();
|
||||
}
|
||||
if($load < 0.01) {
|
||||
|
@ -4213,9 +4215,8 @@ sub compute_number_of_processes {
|
|||
# It took more than 0.01 second to fork a processes on avg.
|
||||
# Give the user a warning. He can press Ctrl-C if this
|
||||
# sucks.
|
||||
print $Global::original_stderr
|
||||
("parallel: Warning: Starting $system_limit processes took > $forktime sec.\n",
|
||||
"Consider adjusting -j. Press CTRL-C to stop.\n");
|
||||
::warning("Starting $system_limit processes took > $forktime sec.\n",
|
||||
"Consider adjusting -j. Press CTRL-C to stop.\n");
|
||||
$slow_spawining_warning_printed = 1;
|
||||
}
|
||||
}
|
||||
|
@ -6128,7 +6129,7 @@ sub start {
|
|||
sub interactive_start {
|
||||
my $command = shift;
|
||||
if($Global::interactive) {
|
||||
print $Global::original_stderr "$command ?...";
|
||||
::status("$command ?...");
|
||||
open(my $tty_fh, "<", "/dev/tty") || ::die_bug("interactive-tty");
|
||||
my $answer = <$tty_fh>;
|
||||
close $tty_fh;
|
||||
|
@ -6179,7 +6180,7 @@ sub tmux_wrap {
|
|||
if($Global::total_running == 0) {
|
||||
$tmux = "tmux new-session -s p$$ -d -n ".
|
||||
::shell_quote_scalar($title);
|
||||
print $Global::original_stderr "See output with: tmux attach -t p$$\n";
|
||||
::status("See output with: tmux attach -t p$$\n");
|
||||
} else {
|
||||
$tmux = "tmux new-window -t p$$ -n ".::shell_quote_scalar($title);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue