Create on_exit method for my dash app

Hello, I am looking for a way to create an on_exit() method in my app that will delete created temporary files when the user exit the app. Does anyone have an idea how?

(any help is appreciated and thank you in advance)


Figuring out when a user has exited an app or when user’s session has ended is actually a pretty complicated topic on its own due to the stateless nature of the HTTP protocol.

As an alternative, I would suggest just deleting any unneeded temp files on a regular schedule, like every day or every week.


That’s what I am going to do for now, I was hoping that I find a method similar to ngOnDestroy in angular,

Thank you