1

I have a flask server that I run using Apache HTTP Server. The python program starts by loading a lot of files into memory (takes about 10 minutes) and then serves some REST API.

Everything works well for some time but after a day or so (or some inactivity?), the python program shuts down. When a new request comes in, the program is re-started (so the first request after some time takes 10 minutes). Caches created in the python program are naturally also empty.

This is my /etc/apache2/sites-available/server.conf (I replaced my actual paths with angle brackets):

<VirtualHost *:80>
     # Add machine's IP address (use ifconfig command)
     ServerName <IP here>

     WSGIDaemonProcess myapp python-home=<path>
     WSGIProcessGroup myapp
     WSGIApplicationGroup %{GLOBAL}

     # Give an alias to to start your website url with
     WSGIScriptAlias <some alias> <path to wsgi>
     <Directory <dir>>
             # set permissions as per apache2.conf file
            Options FollowSymLinks
            AllowOverride None
            Require all granted
     </Directory>
     ErrorLog ${APACHE_LOG_DIR}/error.log
     LogLevel warn
     CustomLog 
</VirtualHost>

This is my wsgi file found under <path to wsgi>:

#! /usr/bin/python3111

import logging
import sys
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '<python application root>')
from flask_server import app as application
application.secret_key = 'anything you wish'

I gues I am missing some configuration line that keeps the python program alive for ever...?

Janothan
  • 446
  • 4
  • 16

0 Answers0