python - trigger a function when pc is shutting down - tkinter -


i have tkinter program when x out of function called using:

root.protocol('wm_delete_window', in_close) 

where in_close procedure called. issue behavior not reproduced when shut down computer. purposes of program, necessary function triggered when program closed or shut machine down.

i'm on python 3.3.3 in case. know how reproduce when it's being shut off? :(

any ideas appreciated!! thanks!!

i not aware of tkinter having specific tool catch system shutdowns suggest. better registering signal handler can catch shutdown signal , trigger in_close function.

(also worth looking here details)

import signal  def in_close(signum = none, frame = none):     # here can attempt gently exit application.     pass  # common signals close program. sig in [signal.sigterm, signal.sigint, signal.sighup, signal.sigquit]:     signal.signal(sig, in_close) 

as pointed out in comments, not windows valid solution. discussions on handling windows shutdown events see:

python - windows shutdown events


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -