2 years ago

#50132

test-img

Jon4thanPP

flask socketio background thread restart or stop while it's sleeping

I've implement a webpage, the user can change settings for how often the background task repeats. The thread always have to wait for the sleep ends, what I want is I can interrupt the sleep, and restart the background task immediately so I can sleep with the newest time from the database, how can I achieve this?

def on_connect():
    global thread
    if thread is None:
        app = current_app._get_current_object()
        thread = socketio.start_background_task(target=background_thread, app=app)
def background_thread:
    with app.app_context():
        while True:
            time = Time.query.first().interval
            socketio.sleep(time)

python

flask-socketio

0 Answers

Your Answer

Accepted video resources