BSD xargs -o (open /dev/tty) is now default for the job running in foreground.

Useful for: ls | parallel -Xuj1 vi.
Unittest for tty commands using the command 'script'.
This commit is contained in:
Ole Tange 2010-09-05 12:22:08 +02:00
parent 32a3f8340b
commit 847841aa11
12 changed files with 123 additions and 45 deletions

View file

@ -1,5 +1,14 @@
sql: Added unittest, --shebang, --version, --help.
parallel: bugfix in unittest.
== SQL ==
/etc/sql/aliases
~/.sql/aliases
== STDIN ==
BSD xargs -o (open /dev/tty) is now default for the job running in foreground.
Useful for: ls | parallel -Xuj1 vi.
Unittest for tty commands using the command 'script'.
== FEX ==
@ -7,10 +16,6 @@ fex syntax for splitting fields
http://www.semicomplete.com/projects/fex/
sql :foo 'select * from bar' | parallel --fex '|{1,2}' do_stuff {2} {1}
== SQL ==
Example:
sql :foo 'select * from bar' | parallel --colsep '\|' do_stuff {4} {1}
== Build ==
build.opensuse.org

View file

@ -103,7 +103,7 @@ cc:Peter Simons <simons@cryp.to>, Sandro Cazzaniga <kharec@mandriva.org>,
Tim Cuthbertson <tim3d.junk@gmail.com>, Ludovic Courtès <ludo@gnu.org>,
Markus Ammer <mkmm@gmx-topmail.de>, Pavel Nuzhdin <pnzhdin@gmail.com>,
Phil Sung <psung@alum.mit.edu>, Michael Shigorin <mike@altlinux.org>,
Andrew McFague <amcfague@wgen.net>
Andrew McFague <amcfague@wgen.net>, Steven M. Christensen <sunfreeware@gmail.com>
Subject: GNU Parallel 2010XXXX released
@ -112,9 +112,6 @@ download at: http://ftp.gnu.org/gnu/parallel/
New in this release:
* sql - a small script to access sql bases from the command line which
is a handy companion to parallel --colsep
* Using --shebang GNU Parallel can be used as the parser for a script.
E.g: #!/usr/bin/parallel --shebang traceroute (followed by lines of
hosts)
@ -124,6 +121,9 @@ New in this release:
* Alt Linux package of GNU Parallel. Thanks to Michael Shigorin <mike
at altlinux dot org>
* Sunfreeware package of GNU Parallel. Thanks to Steven M. Christensen
<sunfreeware at gmail.com>
* Untested CentOS, Fedora, Mandriva, RedHat, and SUSE packages
available through OpenSUSE build service:
https://build.opensuse.org/package/show?package=parallel&project=home%3Atange
@ -134,6 +134,9 @@ New in this release:
* First 1000 views of the intro video
* sql - a small script to access sql bases from the command line which
is a handy companion to parallel --colsep
= About GNU Parallel =
GNU Parallel is a shell tool for executing jobs in parallel using one

View file

@ -1937,10 +1937,14 @@ B<6> find */ -... | fmt 960 1024 | xapply -f -i /dev/tty 'vi' -
B<6> sh <(find */ -... | parallel -s 1024 echo vi)
B<6> find */ -... | parallel -s 1024 -Xuj1 vi
B<7> find ... | xapply -f -5 -i /dev/tty 'vi' - - - - -
B<7> sh <(find ... |parallel -n5 echo vi)
B<7> find ... |parallel -n5 -uj1 vi
B<8> xapply -fn "" /etc/passwd
B<8> parallel -k echo < /etc/passwd
@ -2193,7 +2197,7 @@ sub acquire_semaphore {
sub parse_options {
# Returns: N/A
# Defaults:
$Global::version = 20100822;
$Global::version = 20100901;
$Global::progname = 'parallel';
$Global::debug = 0;
$Global::verbose = 0;
@ -3404,6 +3408,7 @@ sub init_run_jobs {
$Global::total_running = 0;
$Global::total_started = 0;
$Global::total_completed = 0;
$Global::tty_taken = 0;
$SIG{USR1} = \&list_running_jobs;
$SIG{USR2} = \&toggle_progress;
$Global::original_sigterm = $SIG{TERM};
@ -3731,13 +3736,20 @@ sub start_job {
if(@::opt_a and $Private::job_start_sequence == 1) {
# Give STDIN to the first job if using -a
$pid = open3("<&STDIN", ">&STDOUT", ">&STDERR", $command) ||
die("open3 failed. Report a bug to <bug-parallel\@gnu.org>\n");
die("open3 (with -a) failed. Report a bug to <bug-parallel\@gnu.org>\n");
# Re-open to avoid complaining
open STDIN, "<&", $Global::original_stdin
or die "Can't dup \$Global::original_stdin: $!";
} elsif (not $Global::tty_taken and -c "/dev/tty" and
open(DEVTTY, "/dev/tty")) {
# Give /dev/tty to the command if no one else is using it
$pid = open3("<&DEVTTY", ">&STDOUT", ">&STDERR", $command) ||
die("open3 (with /dev/tty) failed. Report a bug to <bug-parallel\@gnu.org>\n");
$Global::tty_taken = $pid;
close DEVTTY;
} else {
$pid = open3(gensym, ">&STDOUT", ">&STDERR", $command) ||
die("open3 failed. Report a bug to <bug-parallel\@gnu.org>\n");
die("open3 (with gensym) failed. Report a bug to <bug-parallel\@gnu.org>\n");
}
debug("started: $command\n");
open STDOUT, ">&", $Global::original_stdout
@ -4278,6 +4290,10 @@ sub reaper {
$Global::running{$stiff} or next;
$Global::running{$stiff}{'exitstatus'} = $? >> 8;
debug("died ($Global::running{$stiff}{'exitstatus'}): $Global::running{$stiff}{'seq'}");
if($stiff == $Global::tty_taken) {
# The process that died had the tty => release it
$Global::tty_taken = 0;
}
# Force printing now if the job failed and we are going to exit
my $print_now = ($Global::running{$stiff}{'exitstatus'} and
$::opt_halt_on_error and $::opt_halt_on_error == 2);

View file

@ -72,9 +72,12 @@ Wait for all commands to complete.
=head1 EXAMPLE: Gzipping *.log
Run one gzip process per CPU core. Block until a CPU core becomes
available.
for i in `ls *.log` ; do
echo $i
sem gzip $i ";" echo done
sem -j+0 gzip $i ";" echo done
done
sem --wait

13
src/sql
View file

@ -6,9 +6,10 @@ sql - execute a command on a database determined by a dburl
=head1 SYNOPSIS
B<sql> [B<-hnr>] [B<--table-size>] [B<--db-size>] [B<-p> I<pass-through>] [B<-s> I<string>] I<dburl> [I<sqlcommand>]
B<sql> [B<-hnr>] [B<--table-size>] [B<--db-size>] [B<-p>
I<pass-through>] [B<-s> I<string>] I<dburl> [I<sqlcommand>]
B<#!/usr/bin/sql> --shebang [options] I<dburl>
B<#!/usr/bin/sql> B<--shebang> [options] I<dburl>
=head1 DESCRIPTION
@ -203,6 +204,12 @@ Then do:
chmod 755 demosql; ./demosql
=head2 Use --colsep to process multiple columns
Use GNU B<parallel>'s B<--colsep> to separate columns:
sql :mydburl 'select * from bar' | parallel --colsep '\t' do_stuff {4} {1}
=head1 REPORTING BUGS
@ -401,7 +408,7 @@ $Global::Initfile && unlink $Global::Initfile;
exit ($err);
sub parse_options {
$Global::version = 20100822;
$Global::version = 20100901;
$Global::progname = 'sql';
# This must be done first as this may exec myself

View file

@ -9,6 +9,7 @@ unittest: ../src/parallel tests-to-run/* wanted-results/*
stdout gawk | mop || (echo gawk is required for unittest; /bin/false)
expect -c 'spawn cat; puts "expect is installed"' || (echo expect is required for unittest; /bin/false)
echo | pv -qL 10 || (echo pv is required for unittest; /bin/false)
echo | script -c echo -q /dev/null || (echo script is required for unittest; /bin/false)
time sh Start.sh
date

View file

@ -23,21 +23,25 @@ echo a
a
echo b
b
### Test stdin goes to first command only
### Test stdin goes to first command only ("-" as argument)
cat -
via first cat
cat -
cat
via cat
echo b
b
cat
via cat
echo b
b
via pseudotty
### Test stdin goes to first command only ("cat" as argument)
echo a
a
cat
via pseudotty
### Test stdin goes to first command only
cat
via cat
echo b
b
cat
via cat
echo b
b
### Bug made 4 5 go before 1 2 3
1
2

View file

@ -49,9 +49,12 @@ echo :sqlunittest mysql://sqlunittest:CB5A1FFFA5A@localhost:3306/sqlunittest >>
sql :sqlunittest "SELECT 'Yes it does' as 'Test if .dburl.aliases works';"
echo "### Test --noheaders --no-headers -n"
sql -n :sqlunittest 'select * from unittest' | parallel --colsep '\t' echo {2} {1}
sql --noheaders :sqlunittest 'select * from unittest' | parallel --colsep '\t' echo {2} {1}
sql --no-headers :sqlunittest 'select * from unittest' | parallel --colsep '\t' echo {2} {1}
sql -n :sqlunittest 'select * from unittest order by id' \
| parallel -k --colsep '\t' echo {2} {1}
sql --noheaders :sqlunittest 'select * from unittest order by id' \
| parallel -k --colsep '\t' echo {2} {1}
sql --no-headers :sqlunittest 'select * from unittest order by id' \
| parallel -k --colsep '\t' echo {2} {1}
echo "### Test --sep -s";
sql --no-headers -s : pg:/// 'select 1,2' | parallel --colsep ':' echo {2} {1}

View file

@ -2,6 +2,8 @@
# Test xargs compatibility
echo '### Test -p --interactive'
cat >/tmp/parallel-script-for-expect <<_EOF
#!/bin/bash
@ -88,12 +90,25 @@ cd input-files/test15
echo 'xargs Expect: 3 1 2'
echo 3 | xargs -P 1 -n 1 -a files cat -
echo 'parallel Expect: 3 1 2'
echo 3 | parallel -k -P 2 -n 1 -a files cat -
echo 'parallel Expect: 3 1 via psedotty 2'
cat >/tmp/parallel-script-for-script <<EOF
#!/bin/bash
echo 3 | parallel -k -P 1 -n 1 -a files cat -
EOF
chmod 755 /tmp/parallel-script-for-script
echo via pseudotty | script -q -f -c /tmp/parallel-script-for-script /dev/null
sleep 1
echo 'xargs Expect: 1 3 2'
echo 3 | xargs -I {} -P 1 -n 1 -a files cat {} -
echo 'parallel Expect: 1 3 2'
echo 'parallel Expect: 1 3 2 via pseudotty'
cat >/tmp/parallel-script-for-script2 <<EOF
#!/bin/bash
echo 3 | parallel -k -I {} -P 1 -n 1 -a files cat {} -
EOF
chmod 755 /tmp/parallel-script-for-script2
echo via pseudotty | script -q -f -c /tmp/parallel-script-for-script2 /dev/null
sleep 1
echo '### Test -i and --replace: Replace with argument'
(echo a; echo END; echo b) | parallel -k -i -eEND echo repl{}ce

View file

@ -9,11 +9,26 @@ parallel --arg-sep ::: -kv ::: 'echo a' 'echo b'
parallel --arg-sep .--- -kv .--- 'echo a' 'echo b'
parallel --argsep ::: -kv ::: 'echo a' 'echo b'
parallel --argsep .--- -kv .--- 'echo a' 'echo b'
echo '### Test stdin goes to first command only'
echo '### Test stdin goes to first command only ("-" as argument)'
cat >/tmp/parallel-script-for-script <<EOF
#!/bin/bash
echo via first cat |parallel -kv cat ::: - -
EOF
chmod 755 /tmp/parallel-script-for-script
echo via pseudotty | script -q -f -c /tmp/parallel-script-for-script /dev/null
sleep 1
echo '### Test stdin goes to first command only ("cat" as argument)'
cat >/tmp/parallel-script-for-script2 <<EOF
#!/bin/bash
echo no output |parallel -kv ::: 'echo a' 'cat'
EOF
chmod 755 /tmp/parallel-script-for-script2
echo via pseudotty | script -q -f -c /tmp/parallel-script-for-script2 /dev/null
sleep 1
echo '### Test stdin goes to first command only'
echo via cat |parallel --arg-sep .--- -kv .--- 'cat' 'echo b'
echo via cat |parallel -kv ::: 'cat' 'echo b'
echo no output |parallel -kv ::: 'echo a' 'cat'
echo '### Bug made 4 5 go before 1 2 3'
parallel -k ::: "sleep 1; echo 1" "echo 2" "echo 3" "echo 4" "echo 5"

View file

@ -166,18 +166,20 @@ xargs Expect: 3 1 2
3
1
2
parallel Expect: 3 1 2
parallel Expect: 3 1 via psedotty 2
3
1
via pseudotty
2
xargs Expect: 1 3 2
1
3
2
parallel Expect: 1 3 2
parallel Expect: 1 3 2 via pseudotty
1
3
2
via pseudotty
### Test -i and --replace: Replace with argument
replace
replace

View file

@ -23,21 +23,25 @@ echo a
a
echo b
b
### Test stdin goes to first command only
### Test stdin goes to first command only ("-" as argument)
cat -
via first cat
cat -
cat
via cat
echo b
b
cat
via cat
echo b
b
via pseudotty
### Test stdin goes to first command only ("cat" as argument)
echo a
a
cat
via pseudotty
### Test stdin goes to first command only
cat
via cat
echo b
b
cat
via cat
echo b
b
### Bug made 4 5 go before 1 2 3
1
2