3

Is there anyway to capture a SIGINT or SIGTERM from the shell in R so that I can try to execute some graceful exit code?

So far, I haven't found anything in my search.

Shuo
  • 491
  • 1
  • 6
  • 16
  • 1
    There is *interrupt* handler in `tryCatch`, see [this working example](https://github.com/jangorecki/logR/blob/03af286b6dfa4246c545e39e385345933f4a7b4b/R/logR.R#L44). I'm not aware of *SIGTERM* handling. – jangorecki Dec 01 '15 at 00:01

1 Answers1

0

It has been a while since you asked and in the meantime someone solved this in a package:

https://github.com/atheriel/sigterm

From the README:

sigterm is an extremely simple package that provides a way to implement just these kinds of operations in response to SIGTERM: when the package is loaded, it will install a signal handler that prevents R from immediately exiting. Users can then periodically check whether a SIGTERM signal has been received and respond appropriately.

FvD
  • 3,697
  • 1
  • 35
  • 53