1

I have a executable program with python 3.7, I want to track if user closed app with taskmanger then program do something.

Actually I used atexit, but this library not working on end task or process ending.

Is there any way to handle this?

my info:

  • python 3.7
  • windows 10
  • pyinstaller 3.4
ttrasn
  • 4,322
  • 4
  • 26
  • 43
  • thanks @eryksun, I saw this answer in [this link](https://stackoverflow.com/questions/12313126/detect-end-process-from-task-manager-in-c-sharp) but how can I use this? can you answer with example ? – ttrasn Dec 27 '18 at 09:56
  • Actually my program runs in background, and its now gui or console. but i think console solution can works for me. – ttrasn Dec 27 '18 at 10:32
  • No, it won't. The console solution requires being attached to a console to get a `CTRL_CLOSE_EVENT` when the console window is closed. For a background program that's not a service, you're going to have to create a thread that owns a hidden window, and the window procedure should handle `WM_CLOSE` by calling `sys.exit`. That should work with taskkill.exe. IIRC, Task Manager requires a visible window. – Eryk Sun Dec 27 '18 at 11:08

0 Answers0