<commit_before>#' Process on multiple cores on one machine
#'
#' This makes use of rzmq messaging and sends requests via TCP/IP
MULTICORE = R6::R6Class("MULTICORE",
    inherit = QSys,

    public = list(
        initialize = function(...) {
            super$initialize(..., node="localhost")
        },

        submit_jobs = function(n_jobs, ...) {
            cmd = quote(clustermq:::worker(private$master, verbose=FALSE))
            for (i in seq_len(n_jobs)) {
                p = parallel::mcparallel(cmd, silent=TRUE, detached=TRUE)
                private$pids = c(private$pids, p$pid)
            }
            private$workers_total = n_jobs
        },

        cleanup = function(quiet=FALSE) {
            success = super$cleanup(quiet=quiet)
            if (success)
                private$pids = NULL
            self$finalize()
        },

        finalize = function() {
            if (length(private$pids) > 0) {
                tools::pskill(private$pids, tools::SIGKILL)
                private$pids = NULL
            }
        }
    ),

    private = list(
        pids = NULL
    )
)<commit_msg>do not detach multicore, collect results (fixes #93)<commit_after>#' Process on multiple cores on one machine
#'
#' This makes use of rzmq messaging and sends requests via TCP/IP
MULTICORE = R6::R6Class("MULTICORE",
    inherit = QSys,

    public = list(
        initialize = function(...) {
            super$initialize(..., node="localhost")
        },

        submit_jobs = function(n_jobs, ...) {
            cmd = quote(clustermq:::worker(private$master, verbose=FALSE))
            for (i in seq_len(n_jobs)) {
                p = parallel::mcparallel(cmd, silent=TRUE)
                private$children[[p$pid]] = p
            }
            private$workers_total = n_jobs
        },

        cleanup = function(quiet=FALSE) {
            success = super$cleanup(quiet=quiet)
            self$finalize()
        },

        finalize = function() {
            for (pid in names(private$children)) {
                res = parallel::mccollect(private$children[[pid]],
                                          wait=FALSE, timeout=0.5)
                if (is.null(res))
                    tools::pskill(pid, tools::SIGKILL)
                private$children[[pid]] = NULL
            }
        }
    ),

    private = list(
        children = list()
    )
)
{'fraction_non_alphanumeric': 0.12174643157010916, 'fraction_numerical': 0.003778337531486146, 'mean_word_length': 1.7079545454545455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5678029', 'n_tokens_mistral': 713, 'n_tokens_neox': 648, 'n_words': 146}