You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If one launches too many callr processes while keeping track of them all, one can run out of file descriptors, although the processes have completed. This results in errors on "Too many open files".
Example
$ ( ulimit-n200; R )
max_fd<- as.integer(system2("ulimit", args="-n", stdout=TRUE))
cat("Max number of open files:", max_fd, "\n")
n<- ceiling(max_fd/3)
processes<-list()
for (iiin1:n) {
cat(sprintf("\r%04d/%04d", ii, n))
process<-callr::r_bg(function() NULL, stdout="|", stderr="|")
process$wait()
void<-process$read_all_output()
void<-process$read_all_error()
process$cleanup()
processes[[ii]] <-process## prevent garbage collector from cleaning up
}
cat("\n")
Results in
Max number of open files: 200
0064/0067Error in `process_initialize(...)`:
! Native call to `processx_exec` failed
Caused by error in `chain_call(...)`:
! processx socketpair (system error 24, Too many open files) @unix/processx.c:433 (processx__make_socketpair)
---
Backtrace:
1. callr::r_bg(function() NULL, stdout = "|", stderr = "|")
2. r_process$new(options = options)
3. local initialize(...)
4. callr:::rp_init(self, private, super, options)
5. callr:::with_envvar(...)
6. base::force(code)
7. base::do.call(...)
8. (function (command = NULL, args = character(), stdin = NULL,
9. processx:::process_initialize(...)
10. processx:::chain_call(...)
11. | base::withCallingHandlers(...)
12. | base::do.call(".Call", list(.NAME, ...))
13. | base::.handleSimpleError(...)
14. | local h(simpleError(msg, call))
15. | processx:::throw_error(err, parent = e)
Execution halted
Wish
Add a method for closing these file connections, e.g. process$cleanup(close_connections = TRUE), similarly to process$kill(close_connections = TRUE).
if (process$has_input_connection()) close(process$get_input_connection())
if (process$has_output_connection()) close(process$get_output_connection())
if (process$has_error_connection()) close(process$get_error_connection())
if (process$has_poll_connection()) close(process$get_poll_connection())
Mostly that it feels like a hack and one needs to know what kill() does if the process is already terminated. For instance, it could be an error to call kill on a terminated process, or it could be a silent no-op.
Activity
gaborcsardi commentedon Jul 12, 2026
Workaround:
EDIT: actually, anything wrong with this?
HenrikBengtsson commentedon Jul 12, 2026
Mostly that it feels like a hack and one needs to know what
kill()does if the process is already terminated. For instance, it could be an error to call kill on a terminated process, or it could be a silent no-op.