Skip to content

A python library for handling graceful shutdown in response to CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, WM_CLOSE, and WM_ENDSESSION

License

Notifications You must be signed in to change notification settings

grintor/win_graceful_shutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

win_graceful_shutdown

A python3 library for handling graceful shutdown in windows in response to: CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, WM_CLOSE, and WM_ENDSESSION

Python has built-in support for exit handlers though the atexit standard library. The problem is, it's pretty hard to get those exit handlers to run reliably on windows. The windows console might close your program via CTRL_C_EVENT or CTRL_BREAK_EVENT, and those are pretty easy to catch and handle. But It might also close your program via CTRL_CLOSE_EVENT, which is a bit more complicated to handle, but not much. Where it starts to get hairy is trying to handle WM_CLOSE, which is what taskkill.exe sends, or WM_ENDSESSION which is what windows sends when it is shutting down or logging off.

This handles all of those situations with just an import. Simply import win_graceful_shutdown and your exit handlers are guaranteed to fire when the program closes.

About

A python library for handling graceful shutdown in response to CTRL_C_EVENT, CTRL_BREAK_EVENT, CTRL_CLOSE_EVENT, WM_CLOSE, and WM_ENDSESSION

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages