0

[solved]Flask app close session after 6 hours of usage regardless of activity

I'm not sure how to close the session after 6 hours, I need to do it even if the user is active as it is part of the security policy for the company I work for. Is this possible?

4th Sep 2020, 4:15 PM
Charlie Crease-huggett
6 Antworten
+ 3
''' I assume you are referring to killing a user session?... If you are trying to terminate your Flask server you can use the same datetime imports and after a 6-hour delta, you would call "sys.exit(0)" ''' from datetime import timedelta from flask import session, app @app.before_request def make_session_permanent(): session.permanent = True app.permanent_session_lifetime = timedelta(hours=6) # https://stackoverflow.com/questions/11783025/is-there-an-easy-way-to-make-sessions-timeout-in-flask
4th Sep 2020, 4:22 PM
Steven M
Steven M - avatar
+ 1
Steven M your right I am trying to kill a user session, but make session permanent resets once a user interacts with the web page, does it not?
4th Sep 2020, 4:50 PM
Charlie Crease-huggett
+ 1
''' Maybe, we can test it by changing the delta to something like 5 minutes... ''' app.permanent_session_lifetime = timedelta(minutes=5)
4th Sep 2020, 5:24 PM
Steven M
Steven M - avatar
+ 1
Steven M ok I'll try that :)
4th Sep 2020, 5:25 PM
Charlie Crease-huggett
+ 1
Steven M your right, I had the wrong syntax and called at the wrong point, thank you
9th Sep 2020, 2:36 PM
Charlie Crease-huggett
+ 1
Charlie Crease-huggett very cool, glad to help 👍🙂👍
9th Sep 2020, 3:01 PM
Steven M
Steven M - avatar