Django: calling a function before session expires
You can't.
This question betrays a fundamental misunderstanding of how both sessions and web applications work. Web code is stateless; there is nothing "running" for any user in between the requests that user makes. If a user doesn't make any requests for longer than the session timeout, the only time the server code knows about it is the next time they actually do make a request: at which point the code will compare the last request time with the current time and either treat the session as valid or expired. If the user goes away and never comes back, there is simply no way the server will ever know.
So i'm using the request.session.set_expiry(NUMBER_OF_SECONDS) in order to check if the user of my webpage has been inactive for a number of seconds and clossing the session when it happens. The problem is that i want to call a function for doing some things jsut before the session expires and i don't know how can I do that.
Thanks in advance!