title: How should I run flask server with socketio?
body: <p>I've built simple webserver in flask according to this tutorial: <a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="nofollow noreferrer">https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world</a>
  Then I realized that I need websockets, because I need real-time communication between client and server. So I installed in my venv flask-socketio library. Then I modified my __init__.py file so it looks like that:</p>
  
  <pre><code>from flask import Flask
  from flask_socketio import SocketIO
  from config import Config
  from flask_sqlalchemy import SQLAlchemy
  from flask_migrate import Migrate
  import logging
  from logging.handlers import RotatingFileHandler
  import os
  
  
  app = Flask(__name__)
  app.config.from_object(Config)
  db = SQLAlchemy(app)
  migrate = Migrate(app, db)
  socketio = SocketIO(app)
  
  if not app.debug:
      if not os.path.exists('logs'):
          os.mkdir('logs')
      file_handler = RotatingFileHandler('logs/webserver.log', maxBytes=10240,
                                         backupCount=10)
      file_handler.setFormatter(logging.Formatter(
          '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
      file_handler.setLevel(logging.INFO)
      app.logger.addHandler(file_handler)
  
      app.logger.setLevel(logging.INFO)
      app.logger.info('Reaction test startup')
  
  from app import routes, models, errors
  
  if __name__ == '__main__':
      socketio.run(app)
  </code></pre>
  
  <p>The problem is that now when I try to run my server using flask run, I get warning:</p>
  
  <p><em>WARNING in __init__: Flask-SocketIO is Running under Werkzeug, WebSocket is not available.</em></p>
  
  <p>I saw other people had this problem too (<a href="https://github.com/miguelgrinberg/Flask-SocketIO/issues/894" rel="nofollow noreferrer">https://github.com/miguelgrinberg/Flask-SocketIO/issues/894</a>), and that I should run my __init__.py script instead of flask run. However, when I try to start my server with "python app/__init__.py", my imports are failing, feels like all dependencies are lost. At first I received message:</p>
  
  <p><em>Traceback (most recent call last):
    File "app/<strong>init</strong>.py", line 3, in 
      from config import Config</em></p>
  
  <p>So I decided to basically rewrite whole config file into __init__.py script. This didn't help though, as after doing it i received message:</p>
  
  <p><em>File "app/<strong>init</strong>.py", line 37, in 
      from app import routes, models, errors
  ModuleNotFoundError: No module named 'app'</em></p>
  
  <p>So I guess rewriting contents of Config.py file wasn't the problem solver. My question is, how should I run my app so that it supports websockets properly without rewriting it from scratch?</p>