flaskwebgui: flaskwebgui is getting killed immediately

Hi, I have just created an single page flask web app all it does is say hello world here is the program

# gui.py
from flask import Flask
from flaskwebgui import FlaskUI
from os import path

b_path = path.join(path.dirname(__file__), 'Browsor', 'chrlauncher.exe')

app = Flask(__name__)
ui = FlaskUI(app, fullscreen=True, start_server='flask',browser_path= b_path)

@app.get('/')
def home():
    return "Hello World"

@app.get('/page')
def page():
    return '''
            This is Another Page
            <a href="/">Go To Home page</a>
            '''


if __name__ == '__main__':
    ui.run()

when i run this file python3 gui.py
it start chromium and program ends after that, which is why it shows Screenshot (71)

and this is on terminal Capture

and i am using this chromium version

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (13 by maintainers)

Most upvoted comments

Version 0.3.0 should fix this issue.

As we can find at flaskwebgui documentation is required to create an additional configuration in order to keep alive de process during the UI execution time.

Inside your static folder you should create a .js file with the following config:

App Path/static/js/keep.alive.js

async function getRequest(url='') {
    const response = await fetch(url, {
      method: 'GET', 
      cache: 'no-cache'
    })
    return response.json()
}

document.addEventListener('DOMContentLoaded', function() {

let url = document.location
let route = "/flaskwebgui-keep-server-alive"
let interval_request = 3 * 1000 //sec

function keep_alive_server(){
    getRequest(url + route)
    .then(data => console.log(data))
}

setInterval(keep_alive_server, interval_request)()

})

Inside every HTML file used by the UI you should add the following lines:

<script src="{{ url_for('static', filename='js/keep.alive.js')}}"></script>

An that’s it!! Hope this work for you!

Change the idle_interval to 50.