flask-uwsgi-websocket icon indicating copy to clipboard operation
flask-uwsgi-websocket copied to clipboard

Problem when the app is in a package

Open white-gecko opened this issue 6 years ago • 0 comments

I've placed my app in a package like that:

- package/
  |- __init__.py
  -- echo.py

The code of echo.py is

from flask import Flask
from flask_uwsgi_websocket import GeventWebSocket

app = Flask(__name__.split('.')[0])

print("name is: {}".format(__name__.split('.')[0]))
print(app.name)
print(app.import_name)

websocket = GeventWebSocket(app)

@websocket.route('/echo')
def echo(ws):
    while True:
        msg = ws.receive()
        ws.send(msg)

@app.route('/hello')
def hallo():
    return 'Hello'

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

As recommended in the flask docu http://flask.pocoo.org/docs/1.0/api/ I use app = Flask(__name__.split('.')[0]) for the name. But flask_uwsgi_websocket will generate the following uwsgi call:

Running: /home/me/.virtualenvs/env/bin/uwsgi --http localhost:5000 --http-websockets --gevent 100 --master  --virtualenv /home/me/.virtualenvs/env --wsgi echo:app

which results in ModuleNotFoundError: No module named 'echo'

Instead of:

Running: /home/me/.virtualenvs/env/bin/uwsgi --http localhost:5000 --http-websockets --gevent 100 --master  --virtualenv /home/me/.virtualenvs/env --wsgi package.echo:app

Starting uwsgi directly with this command works.

white-gecko avatar Nov 26 '18 11:11 white-gecko