gpt4 book ai didi

r - 在 Linux 上从 future_apply() 杀死 future

转载 作者:行者123 更新时间:2023-12-03 09:49:56 25 4
gpt4 key购买 nike

我用 future_lapply()在 Linux 机器上并行我的代码。如果我提前终止进程,只有一名 worker 被释放并且并行进程继续存在。我知道我可以输入tools::pskill(PID)结束每个单独的进程,但这很乏味,因为我在 26 个内核上运行。

如果有办法从 R 对 linux 进行系统调用以获取所有事件的 PID?

我设置了future_lapply像这样:

# set number of workers
works <- 26
plan(multiprocess, workers = works)
future_lapply(datas, function(data) {
# do some long processes
}

如果我终止进程并运行 top我还是会看到:
enter image description here

由于我的并行 session 仍在运行。

更新 session 信息:
version.string R 版本 3.6.2 (2019-12-12)
future 1.12.0
future 应用 1.2.0

最佳答案

我希望这有帮助。

require(future)
works <- 26
plan(multiprocess, workers = works)
future_lapply(datas, function(data) {
# do some long processes
})

# get all PIDs of the r processess
v <- listenv::listenv() # requires listenv package
for (ii in 1:works) {
v[[ii]] %<-% {
Sys.getpid()
}
}

for (i in 1:works) {
#For windows
system(sprintf("taskkill /F /PID %s", v[[i]]))

#For Linux
system(sprintf("kill -9 %s", v[[i]]))
}


祝你有美好的一天。

关于r - 在 Linux 上从 future_apply() 杀死 future ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59652303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com