0

I would like to serve a simple Flask App with uWSGI, in order to have a Simple uWSGI deployment with 4 processes (and hence respond to multiple parallel requests).

I created the "simple_app.py" file containing the application:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello World!"

if __name__ == '__main__':
    app.run()

And a "uwsgi.ini" configuration file:

[uwsgi]
socket = 0.0.0.0:5000
protocol = http
module = simple_app:app
threads = 1
processes = 4

However, when I try to start the server on my local Macbook machine with the Terminal command uwsgi uwsgi.ini , it raises the follwing import error:

*** Operational MODE: preforking ***
Traceback (most recent call last):
  File "./simple_app.py", line 9, in <module>
    from flask import Flask
  File "/anaconda3/lib/python3.7/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
  File "/anaconda3/lib/python3.7/site-packages/jinja2/__init__.py", line 33, in <module>
    from jinja2.environment import Environment, Template
  File "/anaconda3/lib/python3.7/site-packages/jinja2/environment.py", line 15, in <module>
    from jinja2 import nodes
  File "/anaconda3/lib/python3.7/site-packages/jinja2/nodes.py", line 19, in <module>
    from jinja2.utils import Markup
  File "/anaconda3/lib/python3.7/site-packages/jinja2/utils.py", line 16, in <module>
    from jinja2._compat import text_type, string_types, implements_iterator, \
  File "/anaconda3/lib/python3.7/site-packages/jinja2/_compat.py", line 31, in <module>
    import pickle
  File "/anaconda3/lib/python3.7/pickle.py", line 33, in <module>
    from struct import pack, unpack
  File "/anaconda3/lib/python3.7/struct.py", line 13, in <module>
    from _struct import *
ImportError: dlopen(/anaconda3/lib/python3.7/lib-dynload/_struct.cpython-37m-darwin.so, 2): Symbol not found: _PyByteArray_Type
  Referenced from: /anaconda3/lib/python3.7/lib-dynload/_struct.cpython-37m-darwin.so
  Expected in: flat namespace
 in /anaconda3/lib/python3.7/lib-dynload/_struct.cpython-37m-darwin.so
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 ***
    spawned uWSGI worker 1 (pid: 53858, cores: 1)
    spawned uWSGI worker 2 (pid: 53859, cores: 1)
    spawned uWSGI worker 3 (pid: 53860, cores: 1)
    spawned uWSGI worker 4 (pid: 53861, cores: 1)

Both Files are in the same folder of my system; how can I correctly launch the app and receive multiple parallel requests?

Alessandro Ceccarelli
  • 1,775
  • 5
  • 21
  • 41

1 Answers1

0

I've tried to recreate your situation and it's working as expected. Here's my uwsgi.ini file:

[uwsgi]
socket = 192.168.1.219:8888
protocol = http
module = simple_app:app
threads = 1
processes = 4

And here's the simple_app.py file:

from flask import Flask
app = Flask(__name__)


@app.route('/')
def hello():
    return "Hello World!"


if __name__ == '__main__':
    app.run()

And I'm starting up my uwsgi server by uwsgi uwsgi.ini command.

I think the issue is not in uwsgi or your application code, but with the Python or Flask/Jinja installation. Make sure you have properly installed Flask and Jinja in your anaconda environment. You can try to install Python from scratch on your host, or try using Docker and any other virtual environment to isolate Python installation and modules installed on it.

Hett
  • 2,023
  • 3
  • 16
  • 19
  • How can I check the installation? I tried installing both using pip but it reports a successful installation message – Alessandro Ceccarelli Jan 11 '20 at 09:09
  • Unfortunately I'm not a Mac user, but you can try using virtual environment for isolation or any kind of virtual machines (VirtualBox, VMWare Player). It'll free you from the issues you have with Anaconda installation. Or you can try to remove Anaconda and try to install vanilla Python (https://docs.python-guide.org/starting/install3/osx/). – Hett Jan 14 '20 at 07:06
  • Thank you @Hett , I'll give it a try; however, isn't there a way to solve it within Anaconda? – Alessandro Ceccarelli Jan 17 '20 at 09:45
  • I'm not using Anaconda installation, that's why it's a strange behavior for myself as well. You can look through this thread, maybe you'll find something useful for your case: https://stackoverflow.com/questions/50504279/spyder-startup-trouble. Also there's one unanswered thread, maybe that user solved his issue somehow, it's worth to ask him/her: https://stackoverflow.com/questions/59403521/symbol-not-found-pybytearray-type-in-so-when-running-uwsgi. – Hett Jan 17 '20 at 14:30