Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture and signal interrupts? #35

Closed
HenrikBengtsson opened this issue Dec 29, 2015 · 2 comments
Closed

Capture and signal interrupts? #35

HenrikBengtsson opened this issue Dec 29, 2015 · 2 comments

Comments

@HenrikBengtsson
Copy link
Owner

Interrupts (e.g. user interrupts/Ctrl-C, process terminate, ...) may be signaled while a future is evaluated. Should the future package make sure such interrupts are automatically caught and record them such that they are signaled when value() is called, cf. errors?

Details

Interrupts can be caught in R using tryCatch(..., interrupt=...), e.g.

res <- FALSE
res <- tryCatch({
  Sys.sleep(10)
  TRUE
}, interrupt = function(int) {
  str(int)
}, error = function(ex) {
  str(ex)
})

This is somewhat related to Issue #25, but since interrupts are quite different than warnings I think the two ideas should be kept separate.

PS. Added this issue based on a note to myself from 2015-06-18.

@HenrikBengtsson
Copy link
Owner Author

Test with multicore futures as they behave right now if there is an interrupt:

> library("future")

## Start a multicore process
> f <- multicore({ print(1); Sys.sleep(30); print(2); TRUE })
> [1] 1

## Let's find the PID (non-official; don't use in code)
> f$job$pid
[1] 47841

## Let's send an INT(errupt) signal
> system2("kill", c("-INT", f$job$pid))

## Check the value of the multicore future
> value(f)
[1] "fatal error in wrapper code"
attr(,"class")
[1] "try-error"
> traceback()
No traceback available

HenrikBengtsson added a commit that referenced this issue Feb 24, 2016
ROBUSTNESS: Now value() for multicore futures detects if the underlying
forked R process was terminated before completing and if so generates an
informative error messages.
@HenrikBengtsson
Copy link
Owner Author

This is now detected and an error is generated;

> library("future")
> f <- multicore({ print(1); Sys.sleep(30); print(2); TRUE })
> system2("kill", c("-INT", f$job$pid))
[1] 1
> value(f)
Error in value.MulticoreFuture(f) :
Detected an error ('fatal error in wrapper code') by the 'parallel' package while trying
to retrieve the value of a MulticoreFuture ('{; print(1); Sys.sleep(30); print(2); TRUE; }').
This could be because the forked R process that evalutes the future was terminated
before it was completed.
>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant