panel icon indicating copy to clipboard operation
panel copied to clipboard

Add shutdown hook

Open szampier opened this issue 8 months ago • 1 comments

Is your feature request related to a problem? Please describe.

I'm unable to register a callback to perform custom cleanup when the application exits. Specifically, I want to gracefully terminate long-running non-daemon threads started by the application. See topic: https://discourse.holoviz.org/t/shutdown-hook-in-panel/8672/5

Describe the solution you'd like

I suggest to implement a pn.state.on_exit method to register a callback that will be invoked when the application is shut down. A possible implementation is sketched in the linked topic.

Describe alternatives you've considered

An alternative is to use daemon threads, as suggested in the note at the end of the Manual Threading guide, but this is not always desirable because daemon threads are abruptly stopped at shutdown.

Additional context

https://discourse.holoviz.org/t/shutdown-hook-in-panel/8672/5

szampier avatar Mar 30 '25 19:03 szampier

This issue has been mentioned on HoloViz Discourse. There might be relevant details there:

https://discourse.holoviz.org/t/shutdown-hook-in-panel/8672/7

holovizbot avatar Mar 30 '25 19:03 holovizbot