r-lib / gmailr

Access the Gmail RESTful API from R.
https://gmailr.r-lib.org
Other
229 stars 56 forks source link

gmailr does not work when using parallel package #74

Closed jimhester closed 5 years ago

jimhester commented 8 years ago

Not entirely sure if this a bug in gmailr, the curl package or elsewhere.

library(gmailr)
library(parallel)
gmail_auth(scope = 'full')
m = id(messages(user_id = 'me', num_results = 10))
mclapply(m, message)
 *** caught segfault ***
address 0x110, cause 'memory not mapped'

Traceback:
 1: .Call(R_curl_fetch_memory, url, handle, nonblocking)
 2: curl::curl_fetch_memory(url, handle = handle)
 3: request_fetch.write_memory(req$output, req$url, handle)
 4: request_fetch(req$output, req$url, handle)
 5: request_perform(req, hu$handle$handle)
 6: fun(gmail_path(user_id, location), config(token = get_token()),     ...)
 7: gmailr_query(GET, location, user_id, class, ...)
 8: gmailr_GET(c("messages", id), user_id, class = "gmail_message",     query = list(format = format))
 9: gmailr::message(x)
10: eval(expr, env)
11: doTryCatch(return(expr), name, parentenv, handler)
12: tryCatchOne(expr, names, parentenv, handlers[[1L]])
13: tryCatchList(expr, classes, parentenv, handlers)
14: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if (!is.null(call)) {        if (identical(call[[1L]], quote(doTryCatch)))             call <- sys.call(-4L)        dcall <- deparse(call)[1L]        prefix <- paste("Error in", dcall, ": ")        LONG <- 75L        msg <- conditionMessage(e)        sm <- strsplit(msg, "\n")[[1L]]        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")        if (is.na(w))             w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],                 type = "b")        if (w > LONG)             prefix <- paste0(prefix, "\n  ")    }    else prefix <- "Error : "    msg <- paste0(prefix, conditionMessage(e), "\n")    .Internal(seterrmessage(msg[1L]))    if (!silent && identical(getOption("show.error.messages"),         TRUE)) {        cat(msg, file = stderr())        .Internal(printDeferredWarnings())    }    invisible(structure(msg, class = "try-error", condition = e))})
15: try(eval(expr, env), silent = TRUE)
16: sendMaster(try(eval(expr, env), silent = TRUE))
jimhester commented 5 years ago

This is not really a bug in gmailr, just the way forking works on macOS, mclapply is not recommended (https://github.com/jeroen/curl/issues/131)