【问题标题】:Rpy2 in a Flask App: Fatal error: unable to initialize the JITFlask 应用程序中的 Rpy2:致命错误:无法初始化 JIT
【发布时间】:2020-11-05 18:49:30
【问题描述】:

我有一个 Flask 应用程序,我正在尝试添加一个 RESTful 端点,该端点使用 rpy2 从.rds 文件加载模型。当我使用包含import rpy2.robjects as objectspython3 testscript.py 运行我的测试脚本时,它工作正常。但是,当我在我的烧瓶应用程序的文件中尝试相同的导入并使用 FLASK_ENV=development flask run 运行它时,我收到以下错误:

Fatal error: unable to initialize the JIT

我认为这与 Flask 配置和查找 R 有关,以前有人见过吗?

【问题讨论】:

  • 这通常用 rpy2-3.4.2 修复。

标签: python r flask rpy2


【解决方案1】:

在 Web 服务器/服务中使用 Python 时,通常默认使用多线程。

检查文档中的相关部分: https://rpy2.github.io/doc/v3.3.x/html/rinterface.html#multithreading

【讨论】:

    【解决方案2】:

    原帖是正确的。该修复似乎是一个外部修复,例如设置一个不支持多线程的独立服务——例如使用 Redis 服务器。

    这是我的输出,带有 rpy2 3.3.5 python 3.6.8 dash 1.15.0 flask 1.1.2

    [Fri Aug 28 01:51:41.665103 2020] [wsgi:error] [pid 4707] [client 10.93.203.56:53374] Truncated or oversized response headers received from daemon process 'flask_app': /var/www/html/flask_app.wsgi
    [Fri Aug 28 01:58:08.393491 2020] [mpm_prefork:notice] [pid 4702] AH00170: caught SIGWINCH, shutting down gracefully
    [Fri Aug 28 01:58:09.523054 2020] [core:notice] [pid 4754] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
    [Fri Aug 28 01:58:09.523784 2020] [suexec:notice] [pid 4754] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
    [Fri Aug 28 01:58:09.534708 2020] [so:warn] [pid 4754] AH01574: module rewrite_module is already loaded, skipping
    [Fri Aug 28 01:58:09.537129 2020] [lbmethod_heartbeat:notice] [pid 4754] AH02282: No slotmem from mod_heartmonitor
    [Fri Aug 28 01:58:09.539013 2020] [mpm_prefork:notice] [pid 4754] AH00163: Apache/2.4.6 (CentOS) mod_wsgi/4.6.5 Python/3.6 configured -- resuming normal operations
    [Fri Aug 28 01:58:09.539036 2020] [core:notice] [pid 4754] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
    Error: C stack usage  1087224955812 is too close to the limit
    Error: C stack usage  1087224955860 is too close to the limit
    Error: C stack usage  1087224955332 is too close to the limit
    Fatal error: unable to initialize the JIT
    

    已将代码推送到导入的子进程,然后按照此处的建议在包装器中调用:https://rpy2.github.io/doc/v3.3.x/html/rinterface.html#multithreading

    from rpy2.rinterface_lib import openrlib
    
    ....
    
    with openrlib.rlock:
        import farrington2
        d=farrington2.main()
        pass
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 2011-09-17
      相关资源
      最近更新 更多