In help("pskill", package = "tools") is says:

  Only SIGINT and SIGTERM will be defined on Windows, and pskill will
always use the Windows system call TerminateProcess.

As far as I understand it, TerminateProcess [1] terminates the process
"quite abruptly". Specifically, it is not possible for the process to
intercept the termination and gracefully shutdown. In R terms, we
cannot rely on:

tryCatch({
  ...
}, interrupt = function(int) {
  ## cleanup
})

Similarly, it does not look like R itself can exit gracefully. For
example, when signalling pskill(pid, signal = SIGINT) to another R
process, that R process leaves behind its tempdir(). In contrast, if
the user interrupts the process interactively (Ctrl-C), there is an
'interrupt' condition that can be caught, and R cleans up after itself
before exiting.

QUESTION:

Is it possible to gracefully interrupt a child R process on MS
Windows, e.g. a PSOCK cluster node? (I don't think so, but I figure
it's worth asking)


SUGGESTIONS:

Also, if my understanding that TerminateProcess is abrupt is correct,
and there is no way to exit gracefully, would it make sense to clarify
this fact in help("pskill", package = "tools")? Right now you either
have to know how 'TerminateProcess' works, or run various tests on MS
Windows to figure out the current behavior.

Also, would a better signal mapping be:

  Only SIGKILL will be defined on Windows, and pskill will always use
the Windows system call TerminateProcess. Signals SIGINT and SIGTERM
are supported for backward compatible reasons, but are effectively
identical to SIGKILL.

? That would change the expectations on what will happen for people
coming from the POSIX world.

[1] 
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess

/Henrik

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to