How to configure mod_wsgi + apache2 to work with Flask + SocketIO?

Viewed 68

I have an application that's using Flask and Flask-SocketIO. For now I was running it only locally but now I need to host it, in order to give access for other people. I have VPS with apache2 and mod_wsgi.

For now it worked for me locally (I hide insignificant code):

from flask import Flask
from flask_socketio import SocketIO

app = Flask(__name__)
socketio = SocketIO(app)

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

but now I need to import it in to wsgi file on VPS. This is working case without socketIO:

activate_this = '/var/www/mywebsite/mywebsite/venv/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

import sys
sys.path.insert(0,"/var/www/mywebsite/mywebsite")
    
from app import app as application

How can I configure wsgi file to make it work with socketIO aswell? I have tried:

activate_this = '/var/www/mywebsite/mywebsite/venv/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

import sys
sys.path.insert(0,"/var/www/mywebsite/mywebsite")
    
from app import socketio as application

but it leaded to:

TypeError: 'SocketIO' object is not callable

which I think I understand now, why it didn't work, but still I don't know how to configure it properly, what to import as "application" in wsgi file.

0 Answers
Related