Skip to content
Snippets Groups Projects
Commit 658d5dd8 authored by Glenn Proctor's avatar Glenn Proctor
Browse files

Use double-fork (not Open3) to communicate with LSF processes. More reliable...

Use double-fork (not Open3) to communicate with LSF processes. More reliable and no quoting strangeness.
parent c6be6294
No related branches found
No related tags found
No related merge requests found
......@@ -94,14 +94,10 @@ sub submit_exonerate {
my $output = $self->get_class_name() . "_" . $ensembl_type . "_" . "\$LSB_JOBINDEX.map";
my @main_bsub = ( 'bsub', '-J', $unique_name . "[1-$num_jobs]", '-o', "$prefix.%J-%I.out", '-e', "$prefix.%J-%I.err");
my @main_bsub = ( 'bsub', '-J' . $unique_name . "[1-$num_jobs]", '-o', "$prefix.%J-%I.out", '-e', "$prefix.%J-%I.err");
#print "bsub command: " . join(" ", @main_bsub) . "\n\n";
# Use IPC::Open3 to open the process so that we can read and write from/to its stdout/stderr
my ($wtr, $rtr, $etr, $pid);
$pid = open3($wtr, $rtr, $etr, @main_bsub) || die "Cannot call bsub command";
# Create actual execute script to be executed with LSF, and write to pipe
my $main_job = <<EOF;
. /usr/local/lsf/conf/profile.lsf
......@@ -120,24 +116,50 @@ lsrcp /tmp/$output ecs1a:$root_dir/$output
rm -f /tmp/\$LSB_JOBINDEX.$queryfile /tmp/\$LSB_JOBINDEX.$targetfile /tmp/$output
EOF
# TODO make sure query/target are the right way round
print $wtr $main_job;
#print "Job:\n" . $main_job . "\n\n";
close($wtr);
# Wait until bsub has actually run - will print to its stdout ($rtr) and then close it
my $jobid;
while (<$rtr>) {
if (/Job <([0-9]+)> is/) {
$jobid = $1;
print "LSF job ID for main mapping job: $jobid (job array with $num_jobs jobs)\n"
# now submit it
my $jobid = 0;
eval {
my $pid;
my $reader;
local *BSUB;
local *BSUB_READER;
if (($reader = open(BSUB_READER, '-|'))) {
while (<BSUB_READER>) {
if (/^Job <(\d+)> is submitted/) {
$jobid = $1;
print "LSF job ID for main mapping job: $jobid (job array with $num_jobs jobs)\n"
}
}
close(BSUB_READER);
} else {
die("Could not fork : $!\n") unless (defined($reader));
open(STDERR, ">&STDOUT");
if (($pid = open(BSUB, '|-'))) {
print BSUB $main_job;
close BSUB;
if ($? != 0) {
die("bsub exited with non-zero status - job not submitted\n");
}
} else {
if (defined($pid)) {
exec(@main_bsub);
die("Could not exec bsub : $!\n");
} else {
die("Could not fork : $!\n");
}
}
exit(0);
}
}
if (!defined($jobid)) {
print STDERR "Error: could not get LSF job ID for mapping job\n";
};
if ($@) {
# Something went wrong
warn("Job submission failed:\n$@\n");
return 0;
}
return $unique_name;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment