Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden failure when issuing flask run in production environment? #801

Closed
owalerys opened this issue Sep 26, 2018 · 2 comments
Closed

Hidden failure when issuing flask run in production environment? #801

owalerys opened this issue Sep 26, 2018 · 2 comments
Labels

Comments

@owalerys
Copy link

owalerys commented Sep 26, 2018

development

(venv) pi@raspberrypi:~/garden-server $ export FLASK_APP=garden
(venv) pi@raspberrypi:~/garden-server $ export FLASK_ENV=development
(venv) pi@raspberrypi:~/garden-server $ flask run
 * Serving Flask-SocketIO app "garden"
 * Forcing debug mode on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 340-696-311
(23236) wsgi starting up on http://127.0.0.1:5000

production

(venv) pi@raspberrypi:~/garden-server $ export FLASK_APP=garden
(venv) pi@raspberrypi:~/garden-server $ export FLASK_ENV=production
(venv) pi@raspberrypi:~/garden-server $ flask run
 * Serving Flask-SocketIO app "garden"
 * Forcing debug mode off

The last time that I ran flask run and had details cut off like this it was because eventlet was not installed and everything started failing silently without any warning. Is this also a known issue? The thing is is that I'm able to curl http://127.0.0.1:5000 but even with a prod.py script I am seemingly unable to change ports or hosts to use the production server, and I am seriously questioning the missing console loggine.

Both of the above outputs are from using an app factory in garden/__init__.py but I will also paste a prod.py script that I tried to use to fix the problem but did not appear to make a difference.

garden/init.py

import os

from flask import Flask
from flask_socketio import SocketIO

socketio = SocketIO()

def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='dev',
        DATABASE=os.path.join(app.instance_path, 'garden.sqlite'),
    )

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    from . import db
    db.init_app(app)

    from . import auth
    app.register_blueprint(auth.bp)
   
    from . import manager
    manager.init_app(app)

    socketio.init_app(app)
    return app

prod.py

from garden import create_app, socketio

if __name__ == "__main__":
    app = create_app()
    socketio.run(app, host='0.0.0.0', port=8080)

pip freeze

(venv) pi@raspberrypi:~/garden-server $ pip freeze
click==6.7
dnspython==1.15.0
eventlet==0.24.1
Flask==1.0.2
Flask-SocketIO==3.0.2
greenlet==0.4.15
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
monotonic==1.5
pkg-resources==0.0.0
PyCmdMessenger==0.2.4
pyserial==3.4
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1

Even removing gunicorn did not seem to change anything. It was left over from my testing of various production environments.

@miguelgrinberg I saw your PR in the Flask repository in reference to my last Flask issue which seems to be related. Is there an alternate way for me to launch the application and work around the flask run issues without having to downgrade my app to Flask==0.12.4?

Also perhaps useful, this is my directory structure

/garden-server
--prod.py
--/garden
--/--__init__.py

When I tested the prod.py script I would set FLASK_APP=prod.py

@miguelgrinberg
Copy link
Owner

Yes, you can start the application via socketio.run(app), or you can also work with a production webserver, such as gunicorn.

@miguelgrinberg
Copy link
Owner

Starting with Flask-SocketIO 3.2.0, the flask run command is only used to run the Flask development webserver. To use a different webserver use one of the other methods of starting the server, either socketio.run(app) or a recommended method for the webserver of choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants