Skip to content

Commit 3b91c76

Browse files
authored
[scripts] slurm.pl: Catch SIGTERM and SIGINT signals (#4675)
Co-authored-by: WeijiZhuang <zhuangweiji@xiaomi.com>
1 parent 7f3d3da commit 3b91c76

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

egs/wsj/s5/utils/parallel/slurm.pl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
my $jobend;
7373

7474
my $array_job = 0;
75+
my $sge_job_id;
7576

7677
sub print_usage() {
7778
print STDERR
@@ -101,6 +102,14 @@ sub exec_command {
101102
# To get the actual exit value, shift right by eight bits.
102103
($_ = `$command 2>&1`, $? >> 8);
103104
}
105+
sub caught_signal {
106+
if ( defined $sge_job_id ) { # Signal trapped after submitting jobs
107+
my $signal = $!;
108+
system ("scancel $sge_job_id");
109+
print STDERR "Caught a signal: $signal , deleting SLURM task: $sge_job_id and exiting\n";
110+
exit(2);
111+
}
112+
}
104113

105114
if (@ARGV < 2) {
106115
print_usage();
@@ -194,6 +203,8 @@ sub exec_command {
194203
# A more detailed description of the ways the options would be handled is at
195204
# the top of this file.
196205

206+
$SIG{INT} = \&caught_signal;
207+
$SIG{TERM} = \&caught_signal;
197208
my $opened_config_file = 1;
198209

199210
open CONFIG, "<$config" or $opened_config_file = 0;
@@ -434,7 +445,6 @@ sub exec_command {
434445
exit(1);
435446
}
436447

437-
my $sge_job_id;
438448
if (! $sync) { # We're not submitting with -sync y, so we
439449
# need to wait for the jobs to finish. We wait for the
440450
# sync-files we "touched" in the script to exist.

0 commit comments

Comments
 (0)