Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Apache restarting after page interactions

Hello,

I have successfully made a multi-page interactive website, hosted on my own computer. The website has sliders, interactive fields, redis caching and for the most part works well.

The website is provided by an apache server running on CentOS. The problem I am having is that the server seems to “restart” quite often, both when changing pages and when interacting with the page. However, sometimes the server does not “restart”. The problem is that this “restarting” is slowing down the whole experience, as it takes ~2 seconds to restart!

Here is part of the app1.py:

import flask      # 0.1 seconds to import
import dash       # 0.9 seconds to import
import dash_core_components as dcc   # 0.1 seconds to import
import dash_html_components as html  # 1 second to import
import plotly.graph_objs as go       # 0 seconds to import :-)

print('#### Server has restarted')

server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)
# Allow callbacks for children which don't yet exist
app.config.suppress_callback_exceptions = True

LOST OF CONTENT

app.layout = serve_layout

if __name__ == '__main__':
    app.run_server(debug=False, use_reloader=False)  # these don't seem to change the experience

When I look in the /etc/httpd/logs/error_log I see a lot of #### Server has restarted from the above print.

I am new to both dash and the apache web development, but have used python a lot.

Perhaps I should use mod_wsgi-express instead of apache??

All the best,
Peter

EDIT:

my app.wsgi file is:

#!/usr/bin/python
import sys
sys.path.insert(0,"/var/www/FLASKAPPS/PFIT_Viewer/")
#from app1 import app as application
from app1 import server as application

and /etc/httpd/sites-enabled/app1.conf:

<VirtualHost *:80>
    ServerName xxx
    WSGIScriptAlias / /var/www/app1/app1.wsgi
    WSGIScriptReloading Off  # this made no difference!
    <Directory /var/www/app1/>
      Order allow,deny
      Allow from all
    </Directory>
    Alias /static /var/www/app1/
    <Directory /var/www/app1/static/>
      Order allow,deny
      Allow from all
    </Directory>
</VirtualHost>

Just in case anyone else finds this problem. The solution is to serve the website as as mod_wsgi. Details are here:
http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/

1 Like