title: Multithreaded Flask application causes stack error in rpy2 R process
body: <p>Essentially the same error as here, but those solutions do not provide enough information to replicate a working example: <a href="https://stackoverflow.com/questions/62928973/rpy2-in-a-flask-app-fatal-error-unable-to-initialize-the-jit/">Rpy2 in a Flask App: Fatal error: unable to initialize the JIT</a></p>
  <p>Within my Flask app, using the rpy2.rinterface module, whenever I intialize R I receive the same stack usage error:</p>
  <pre><code>import rpy2.rinterface as rinterface 
  from rpy2.rinterface_lib import openrlib
  
  with openrlib.rlock: 
      rinterface.initr()
  
  Error: C stack usage 664510795892 is too close to the limit Fatal error: unable to initialize the JIT
  </code></pre>
  <p>rinterface is the low-level R hook in rpy2, but the higher-level robjects module gives the same error. I've tried wrapping the context lock and R initialization in a Process from the multiprocessing module, but have the same issue. Docs say that a multithreaded environment will cause problems for R: <a href="https://rpy2.github.io/doc/v3.3.x/html/rinterface.html#multithreading" rel="nofollow noreferrer">https://rpy2.github.io/doc/v3.3.x/html/rinterface.html#multithreading</a>
  But the context manager doesn't seem to be preventing the issue with interfacing with R</p>