python - 如何配置一个 uWSGI 站点来使用与构建 uWSGI 时不同的 Python 解释器? (uWSGI + virtualenv + emperor)

标签 python flask virtualenv uwsgi

我们的应用程序是为 Python 2.7 编写的。它有一个配置为使用 Python 2.7 的 virtualenv。系统安装的 uWSGI 是用 Python 2.6 构建的。 It seems that this is a problem.我们可以卸载/重新安装 uWSGI 以使用 Python 2.7,但是当我们最终拥有 Python 3 站点时会发生什么?这不是 virtualenv 的用途吗?我们可以在 virtualenv 中安装一个单独的 uWSGI 实例,但不清楚它是如何工作的——需要在启动时激活它,以及它如何与 emperor 一起工作?我们应该使用 uWSGI 关键字“unprivileged-binary-patch”吗?

我们如何配置 uWSGI 以便我们可以使用不同的 Python 解释器运行多个应用程序?

我们在从 uWSGI 启动时看到了这个问题。

Python version: 2.6.9 (unknown, Oct 29 2013, 19:58:13)  [GCC 4.6.3 20120306 (Red
 Hat 4.6.3-2)]
Set PythonHome to /var/local/virtualenv/myapp
Python main interpreter initialized at 0xf86790
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 655200 bytes (639 KB) for 8 cores
*** Operational MODE: preforking ***
initialized 137 metrics
Traceback (most recent call last):
  File "/var/local/myapp/cgi/myapp.wsgi", line 6, in <module>
    from myapp import create_app
  File "./myapp/__init__.py", line 3, in <module>
    from app import create_app
  File "./myapp/app.py", line 1, in <module>
    import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
gracefully (RE)spawned uWSGI master process (pid: 2500)
spawned uWSGI worker 1 (pid: 2521, cores: 1)
spawned uWSGI worker 2 (pid: 2522, cores: 1)
spawned uWSGI worker 3 (pid: 2523, cores: 1)
spawned uWSGI worker 4 (pid: 2524, cores: 1)
spawned uWSGI worker 5 (pid: 2525, cores: 1)
spawned uWSGI worker 6 (pid: 2526, cores: 1)
spawned uWSGI worker 7 (pid: 2527, cores: 1)
spawned uWSGI worker 8 (pid: 2528, cores: 1)
metrics collector thread started
*** Stats server enabled on 127.0.0.1:9191 fd: 27 ***
spawned uWSGI http 1 (pid: 2530)

该应用程序是用 Flask 编写的,并使用 create_app 模式启动它。该应用程序在使用 virtualenv 和内置于端口 5000 上的 Flask 中的开发者 Web 服务器时运行良好。

ini 文件如下所示:

[uwsgi]
chdir = /var/local/%n
callable = create_app
virtualenv=/var/local/virtualenv/%n
wsgi-file = /var/local/%n/cgi/%n.wsgi
master = true
daemonize = /var/log/uwsgi/%n.log
pidfile = /var/run/uwsgi/%n.pid
http = :9090

我们想以皇帝模式运行网站。这是皇帝的 ini 文件:

[uwsgi]
emperor = /etc/uwsgi/vassals

pidfile = /var/run/uwsgi/%n.pid
daemonize = /var/log/uwsgi/%n.log

最佳答案

最好的方法是为每个 python 版本都有一个 uWSGI 插件(就像你的发行版中的 uWSGI 包一样)

(旧站点上的文档) http://projects.unbit.it/uwsgi/wiki/MultiPython

关于python - 如何配置一个 uWSGI 站点来使用与构建 uWSGI 时不同的 Python 解释器? (uWSGI + virtualenv + emperor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20099858/

相关文章:

python - 使用 s3boto 的 Django 存储忽略 MEDIA_URL

flask - Airflow 向 base_url 添加前缀

javascript - 在 React 中刷新后保留 'loggedIn' 状态

python - 使用 virtualenv 安装某些包

Python (Windows Server) Virtualenv 无法识别 Django 已安装

python - 将字符串与适用于 Python 2 和 3 的字节进行比较

python - 带星数的聚集数索引

python - Flask-WTF model_form、Sqlalchemy 和外键

python - 如何在 python Flask 中安排定时事件?

python - 如何用诗歌管理可编辑的共享库?