processx icon indicating copy to clipboard operation
processx copied to clipboard

Kill processes on unload, on Windows

Open gaborcsardi opened this issue 8 years ago • 7 comments

gaborcsardi avatar May 18 '17 12:05 gaborcsardi

Guess the callr package fails to really kill the process on Windows is due to the same reason. Minimal Repro:

callr::r(function() {
  message("hi")
  Sys.sleep(3)
  message("hi2")
  Sys.sleep(3)
  message("hi3")
}, timeout = 1)
#> Error: callr timed out hi
#> hi2
#> hi3
sessionInfo()
#> R version 3.4.1 (2017-06-30)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 7 x64 (build 7601) Service Pack 1
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936 
#> [2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936   
#> [3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
#> [4] LC_NUMERIC=C                                                   
#> [5] LC_TIME=Chinese (Simplified)_People's Republic of China.936    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_0.12.13          crayon_1.3.4          digest_0.6.13        
#>  [4] rprojroot_1.3-2       assertthat_0.2.0      R6_2.2.2             
#>  [7] backports_1.1.2       magrittr_1.5          evaluate_0.10.1      
#> [10] debugme_1.1.0         stringi_1.1.6         rstudioapi_0.7.0-9000
#> [13] callr_1.0.0.9000      rmarkdown_1.8         tools_3.4.1          
#> [16] stringr_1.2.0         yaml_2.1.16           compiler_3.4.1       
#> [19] processx_3.0.1        htmltools_0.3.6       knitr_1.18

shrektan avatar Jan 17 '18 04:01 shrektan

Confirmed. Interesting. This is actually tested, and it does kill some processes, but seems like it does not kill R:

> system.time(processx::run("src/tools/px.exe", c("sleep", "100"), timeout = 1))
Error in processx::run("src/tools/px.exe", c("sleep", "100"), timeout = 1) :
  System command timeout
Timing stopped at: 0 0 1.05
> system.time(processx::run(file.path(R.home("bin"), "R"), c("-q", "-e", "Sys.sleep(3)"), timeout = 1))
Error in processx::run(file.path(R.home("bin"), "R"), c("-q", "-e", "Sys.sleep(3)"),  :
  System command timeout
Timing stopped at: 0.02 0 3.3

gaborcsardi avatar Jan 17 '18 10:01 gaborcsardi

This is a bug, btw, and does not have much to do with this issue.

gaborcsardi avatar Jan 17 '18 10:01 gaborcsardi

It does kill the R process with the same pid reported by the processx object.

It's very weird. Although I can see the R process has been killed in the task manager of Windows, it seems like it's still running in the background...

shrektan avatar Jan 17 '18 12:01 shrektan

The CRAN version of processx works fine for this case since it's using tools::pskill(). Do you need me to open a new issue because it's not much to do with the current?

shrektan avatar Jan 20 '18 02:01 shrektan

@shrektan opened a separate issue for this: #96

gaborcsardi avatar Jan 23 '18 13:01 gaborcsardi

Thanks!

shrektan avatar Jan 23 '18 21:01 shrektan