Skip to content

Commit 92fcfc1

Browse files
Handle crashed and killed batchtools futures [#95]
1 parent 7cf57a4 commit 92fcfc1

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.2-9912
2+
Version: 0.12.2-9913
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ importFrom(batchtools,waitForJobs)
8888
importFrom(future,FutureBackend)
8989
importFrom(future,FutureError)
9090
importFrom(future,FutureInterruptError)
91+
importFrom(future,FutureLaunchError)
9192
importFrom(future,cancel)
9293
importFrom(future,interruptFuture)
9394
importFrom(future,launchFuture)

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
* Canceling of batchtools future will now interrupt them by default,
1515
for backends where it is supported.
16-
16+
1717

1818
# Version 0.12.2 [2025-06-06]
1919

R/BatchtoolsFutureBackend-class.R

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ result.BatchtoolsFuture <- function(future, cleanup = TRUE, ...) {
699699
} ## result()
700700

701701

702-
#' @importFrom future FutureInterruptError
702+
#' @importFrom future FutureInterruptError FutureLaunchError
703703
#' @importFrom batchtools loadResult waitForJobs
704704
#' @importFrom utils tail
705705
await <- function(future, cleanup = TRUE, ...) {
@@ -778,8 +778,36 @@ await <- function(future, cleanup = TRUE, ...) {
778778
class(future)[1], label, loggedError(future))
779779
stop(BatchtoolsFutureError(msg, future = future))
780780
} else if ("expired" %in% stat) {
781+
## NOTE: If a batchtools job crashes or is killed, then it gets status
782+
## 'expired'. In such cases, we should throw a FutureInterruptError.
783+
##
784+
## I think we might also see 'expired' for jobs that fail to launch,
785+
## which in case we should throw a FutureLaunchError. I'm not sure
786+
## how we can distinguish the two right now, but I'll assume that
787+
## started jobs have a 'submitted' or 'started' status flag too,
788+
## whereas jobs that failed to launch won't. /HB 2025-07-15
789+
790+
output <- loggedOutput(future)
791+
hint <- unlist(strsplit(output, split = "\n", fixed = TRUE))
792+
hint <- hint[nzchar(hint)]
793+
hint <- tail(hint, n = getOption("future.batchtools.expiration.tail", 48L))
794+
if (length(hint) > 0) {
795+
hint <- c("The last few lines of the logged output:", hint)
796+
hint <- paste(hint, collapse = "\n")
797+
} else {
798+
hint <- "No logged output exist"
799+
}
800+
801+
if (any(c("submitted", "started") %in% stat)) {
802+
msg <- sprintf("Future (%s) of class %s expired, which indicates that it crashed or was killed. %s", label, class(future)[1], hint)
803+
stop(FutureInterruptError(msg, future = future))
804+
} else {
805+
msg <- sprintf("Future (%s) of class %s failed to launch. %s", label, class(future)[1], hint)
806+
stop(FutureLaunchError(msg, future = future))
807+
}
808+
781809
cleanup <- FALSE
782-
msg <- sprintf("BatchtoolsExpiration: Future ('%s') expired (registry path %s).", label, reg$file.dir)
810+
msg <- sprintf("BatchtoolsExpiration: Future ('%s') expired (registry path %s)", label, reg$file.dir)
783811
output <- loggedOutput(future)
784812
hint <- unlist(strsplit(output, split = "\n", fixed = TRUE))
785813
hint <- hint[nzchar(hint)]

0 commit comments

Comments
 (0)