-
Notifications
You must be signed in to change notification settings - Fork 8
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
Multi-threaded dump files #39
Comments
Thanks for reporting this issue (excellent observation - I've never spent a thought about name clashes due to multi-threading). It would be great if you could provide a minimal reproducible example so that I can examine different solution options. I am also thinking about another R option to support configuring the file naming pattern for the dump file (which would support a simple work-around to change the name prefix for each thread/sub process without making It seems difficult to find out the tread [Edit: Removed "and process"] ID of the R session with base R (without using a specialized package) and I want to minimize the package dependencies. |
Internal implementation notes (will be updated incrementally):
|
Slightly over-engineered reproducible example (suggest saving to file in empty directory & running): library(future)
library(tryCatchLog)
plan(multiprocess)
options(tryCatchLog.write.error.dump.file = TRUE)
for(ii in 1:10) {
f1 <- future({ tryCatchLog({ stop("Error 1") }) }, lazy = TRUE)
f2 <- future({ tryCatchLog({ stop("Error 2") }) }, lazy = TRUE)
resolve(list(f1, f2))
dumpFiles <- list.files("./", pattern = "dump_.*\\.rda")
cat("Found", length(dumpFiles), "dump files\n")
sapply(dumpFiles, function(dumpFile) {
e <- new.env(parent = emptyenv())
load(dumpFile, envir = e)
cat("\t[", dumpFile, "] Error in file is:", e$last.dump[[length(e$last.dump)]]$log.message, "\n")
})
sapply(dumpFiles, file.remove)
} Note: I used the HenrikBengtsson/future package (available on CRAN) as a source of producing threads |
Bug fixed. Diagnostics: Dump files may be overwritten when multiple errors occur at the same second in the same or parallel processes. Solution: Create a (hopefully) unique dump file name incl. milliseconds and the process id in the file name, eg.: |
When running in a multi-threaded mode (eg. using future package), any error files get botched if more than one thread throws an error at a time as the file names become non-unique.
Consider adding thread handling or add a process ID to filename (or append milliseconds and use a file exists loop which by its nature will change the filename by a few millis and thus make filenames unique)
The text was updated successfully, but these errors were encountered: