futureverse / futureverse/future.batchtools

SGE template: Signal SIGINT by default to allow R to catch it gracefully

Aperta
#104 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
feature/resources scheduler/sge
Lingua principale
R
Stelle
87
Fork
10
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

When a job is approaching it's maximum run-time limit, and `--notify` has been specified, SGE sends a `SIGUSR2` 60 seconds before sending a `SIGKILL` (abrupt; not capturable).

R code cannot handle `SIGUSR2` signals, only `SIGINT`. If SGE would signal `SIGINT` instead, we could capture it internally as an `interrupt` condition, and using `tryCatch(..., interrupt = ...)`, `on.exit()`, and likes to gracefully exit, e.g. close connections, checkpoint intermediate results, etc.

# Idea

Update the default SGE template to signal `SIGINT`. Unlike Slurm, there is no user-facing option to change the type of signal in SGE. But we could use Bash traps to capture the `SIGUSR2` and re-signal it as `SIGINT`. Something like:

```bash
#! /bin/bash
...
## Request SGE to send warning signals (SIGUSR2) before run-time limit termination
#$ -notify
...

# Function to catch SGE run-time signals and re-signal as SIGINT
forward_sigint() {
echo "Caught SGE run-time signal. Re-signal as SIGINT to R..."
kill -2 "${R_PID}" 2>/dev/null || true
wait "${R_PID}"
res=$?
echo " - exit code (from signal handler): ${res}"
exit "${res}"
}

# Trap SGE run-time limit signals
trap forward_sigint SIGUSR2

<%= rscript_call %> -e 'batchtools::doJobCollection("<%= uri %>")' &
R_PID=$!
wait "${R_PID}"
res=$?

# Clear the trap on normal exit
trap - SIGUSR2
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con il template SGE predefinito e segui il modo in cui `rscript_call`, `uri` e `batchtools::doJobCollection` avviano il job. Esamina il trap Bash `SIGUSR2` proposto e il flusso di attesa del processo, quindi verifica che un limite di tempo imminente raggiunga R come `SIGINT` e consenta una pulizia ordinata prima della terminazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
bash, r
Ambito
distributed-systems
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
50/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.