如何配置uWSGI站点以使用不同于uWSGI构建的Python解释器? (uWSGI + virtualenv + emperor)

时间:2013-11-20 15:21:45

标签: python flask virtualenv uwsgi

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

2 个答案:

答案 0 :(得分:2)

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

(旧网站上的doc) http://projects.unbit.it/uwsgi/wiki/MultiPython

答案 1 :(得分:1)

您可以在其他python / virtualenv版本中安装uwsgi。然后你可以在可堆叠模式下使用uwsgi emperor:

[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
unprivileged-binary-patch = /var/local/virtualenv/bin/uwsgi