I guess you mean Bottle and not PyBottle.
There are soultion for this and i would recommend Flask,
that has better support for stuff like this like Flask-SocketIO and jQuery + socket.io on the client side.
Also mention Celery that work well with Flask.
The topic of running background live update/stream tasks is complex.
If new to Python and web-develoment dos not help![Wink Wink](https://python-forum.io/images/smilies/wink.png)
Can show a solution that call a Python function on server side every 10-sec.
This is using Ajax to no reload browser,and done with jQuery on client side.
To help keep it clean
Will prevent all future AJAX requests from being cached.
setTimeout( will execute a script only one time) is better setInterval().
app.py:
Quote:But do not I ( unnecessarily ) create a new web-server instance?Yes it's not good and unnecessarily to create a web-server instance for every update.
There are soultion for this and i would recommend Flask,
that has better support for stuff like this like Flask-SocketIO and jQuery + socket.io on the client side.
Also mention Celery that work well with Flask.
The topic of running background live update/stream tasks is complex.
If new to Python and web-develoment dos not help
![Wink Wink](https://python-forum.io/images/smilies/wink.png)
Can show a solution that call a Python function on server side every 10-sec.
This is using Ajax to no reload browser,and done with jQuery on client side.
To help keep it clean
$.ajaxSetup({ cache: false });
Will prevent all future AJAX requests from being cached.
setTimeout( will execute a script only one time) is better setInterval().
app.py:
from flask import Flask, render_template, jsonify, request import random app = Flask(__name__) @app.route("/") def test_job(): return render_template('index.html') @app.route('/stuff', methods=['GET']) def stuff(): '''Here stuff to be send to browser''' val_random = random.random() return jsonify(val_random=val_random) if __name__ == "__main__": app.run(debug=True)index.html:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style.css') }}" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <title>Show updated random number</title> </head> <body> <div class="table"> <p id="rand_value">Value</p> <button>Push to start random update</button> </div> </body> <script> $.ajaxSetup({ cache: false }); $(document).ready(function () { $("button").click(function update_values() { $.getJSON('/stuff', function (dat) { $("#rand_value").text(dat['val_random']); }); var interval = setTimeout(update_values, 10000); }); }); </script> </html>