-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
46 lines (32 loc) · 1.36 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import win_graceful_shutdown # this needs to be imported first so that any exit handlers created by modules imported after will surely run
import lovely_logger as log # pip install lovely_logger
import win32con # pip install pywin32
import time
import atexit
import os
log.init('example.log')
def cleanup():
if win_graceful_shutdown.EXIT_REASON == win32con.CTRL_C_EVENT:
log.w('got win32con.CTRL_C_EVENT')
if win_graceful_shutdown.EXIT_REASON == win32con.CTRL_BREAK_EVENT:
log.w('got win32con.CTRL_BREAK_EVENT')
if win_graceful_shutdown.EXIT_REASON == win32con.CTRL_CLOSE_EVENT:
log.w('got win32con.CTRL_CLOSE_EVENT')
if win_graceful_shutdown.EXIT_REASON == win32con.WM_CLOSE:
log.w('got win32con.WM_CLOSE')
if win_graceful_shutdown.EXIT_REASON == win32con.WM_ENDSESSION:
log.w('got win32con.WM_ENDSESSION')
for x in range(3):
log.i('cleaning up...')
time.sleep(1)
log.d ("example has ended")
atexit.register(cleanup)
log.d ("example has started")
print('\n')
print(f"Our pid is {os.getpid()}. Try killing it with 'taskkill /pid:{os.getpid()}'")
print('Or try hitting ctrl-c or ctrl-break')
print('Or try closing this window')
print('Or restart this process using pythonw.exe (no console window) and try logging out/rebooting then look in test.log')
print('\n')
while True:
time.sleep(1)