Muhammed Abad
Muhammed Abad

Reputation: 81

uWSGI and Python > 3.4

I have a django project currently running with the following configuration:

I installed Python 3.6.1 from source and created a new virtual environment with python 3.6 (I use virtualenvwrapper), but I seem to have some trouble getting the project to start up with uwsgi.

Config file is as follows:

[uwsgi]
plugins = python3
project = %n
module = myapp.wsgi:application
home = path_to_new_env
socket = /var/run/uwsgi-%n.sock
chdir = path_to_new_env/myapp/myapp
processes = 4
max-requests = 5000
chmod-socket = 666
chown-socket = user:user
master = True
vacuum = True
logto = /var/log/%n_LOG.log
buffer-size = 32768

I was under the impression that the python3 plugin would include support for python 3.6, but the log indicates that the Python 3.4.x interpreter is still being used.

In my list of installed uwsgi plugins, I see support for python 2, 3 and 3.4 but nothing more. I'm not sure what needs to be done to have the correct interpreter set on startup.

Any advice would be appreciated.

UPDATE: I've tried building a uwsgi plugin for python 3.6:

root@app:~# PYTHON=python3.6 uwsgi --build-plugin "/root/uwsgi-2.0.15/plugins/python python36"
*** uWSGI building and linking plugin from /root/uwsgi-2.0.15/plugins/python ***
[gcc -pthread] python36_plugin.so
/root/uwsgi-2.0.15/plugins/python/python_plugin.c: In function ‘uwsgi_python_atexit’:
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:380:11: error: ‘struct uwsgi_server’ has no member named ‘skip_atexit_teardown’
  if (uwsgi.skip_atexit_teardown)
           ^
/root/uwsgi-2.0.15/plugins/python/python_plugin.c: At top level:
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: unknown field ‘worker’ specified in initializer
  .worker = uwsgi_python_worker,
  ^
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: initialization from incompatible pointer type [-Werror]
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: (near initialization for ‘python36_plugin.exception_class’) [-Werror]
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: initialized field overwritten [-Werror=override-init]
/root/uwsgi-2.0.15/plugins/python/python_plugin.c:2018:2: error: (near initialization for ‘python36_plugin.exception_class’) [-Werror=override-init]
cc1: all warnings being treated as errors
/root/uwsgi-2.0.15/plugins/python/uwsgi_pymodule.c: In function ‘py_uwsgi_spooler_get_task’:
/root/uwsgi-2.0.15/plugins/python/uwsgi_pymodule.c:2107:2: error: implicit declaration of function ‘uwsgi_spooler_read_header’ [-Werror=implicit-function-declaration]
  if (uwsgi_spooler_read_header(task_path, spool_fd, &uh) ||
  ^
/root/uwsgi-2.0.15/plugins/python/uwsgi_pymodule.c:2108:3: error: implicit declaration of function ‘uwsgi_spooler_read_content’ [-Werror=implicit-function-declaration]
   uwsgi_spooler_read_content(spool_fd, spool_buf, &body, &body_len, &uh, &task_stat)) {
   ^
cc1: all warnings being treated as errors
*** unable to build python36 plugin ***

Upvotes: 6

Views: 5825

Answers (2)

Evhz
Evhz

Reputation: 9284

I've recently came up with a solution to python3.6 apps with server.

wget https://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar -xvzf uwsgi-latest.tar.gz

mv uwsgi-2.0.17 uwsgi
cd uwsgi
make PROFILE=nolang # no language defaults allows flexibility for python versions

PYTHON=python3.6 # or --> PYTHON=/usr/bin/python3.6

./uwsgi --build-plugin "plugins/python python36"
mv python36_plugin.so plugins/python
cd ..
sudo mv uwsgi /usr/local
sudo ln -s /usr/local/uwsgi/uwsgi /usr/local/bin/uwsgi

Then, you can use it in configuration files as follows:

[uwsgi]

plugins-dir = /usr/local/uwsgi/plugins/python
plugin = python36

Mimic this process for any other python version you'd like to have available on the uwsgi server.
More help here.

Upvotes: 6

Muhammed Abad
Muhammed Abad

Reputation: 81

Solution:

1) Download uwsgi source tarball

2) Follow build instructions here

Note that for python3.6, you need to configure python with the --enable-shared flag as well as declare an extra environment variable before building the uWsgi plugin: export CFLAGS="$CFLAGS -fPIC"

3) Install new uwsgi binary with supported plugins: cp uwsgi /usr/local/bin/

Upvotes: 0

Related Questions