title: Parallel processing in R calling reticulate python function
body: <p>I'm using <code>reticulate</code> in RMarkdown and am trying to run a locally defined Python function with parallel processing. I've looked around and <a href="https://stackoverflow.com/questions/51043043/parallel-processing-in-r-shiny-calling-python-script/51051700">this answer</a> is the closest I've found to solving my issue except the function I'm using is not defined in a separate Python script, but rather within Rmarkdown. Below is a simplified example using <code>llply</code>, which gives me the error <code>Error in unserialize(socklist[[n]]) : error reading from connection</code>. </p>
  
  <p>I have also tried <code>foreach()</code>, which doesn't recognize the <code>py$</code> object even with <code>reticulate::py$function</code>.</p>
  
  <p>I have also tried <code>mclapply</code> and <code>pbmcapply</code>, which appear to run and engage all cores, but they keep hanging and won't finish.</p>
  
  <pre><code>```{r}
      library(reticulate)
      library(doParallel)
      library(foreach)
      library(plyr)
  ```
  
  ```{python}
  def myFn1(x):
      return(sqrt(x))
  ```
  
  ```{r}
  cl &lt;- makeCluster(detectCores())
  registerDoParallel(cl)
  llply(list(2, 3, 4), .fun=reticulate::py$myFn1, .parallel=TRUE)
  stopCluster(cl)
  ```
  </code></pre>
  
  <p>I am not very knowledgeable about reticulate or parallel processing and I would be really grateful for any help.</p>