-
Notifications
You must be signed in to change notification settings - Fork 8
/
GUI-test
executable file
·84 lines (53 loc) · 2.1 KB
/
GUI-test
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
###############################################################################
###############################################################################
# Copyright (c) 2024, Andy Schroder
# See the file README.md for licensing information.
###############################################################################
###############################################################################
################################################################
# import modules
################################################################
# dc must be the first module initialized and then immediately set the mode
import dc,sys
dc.mode='GUI-test'
# dc.common must be the second imported module because it reads the config
from dc.common import GUI, logger, console
from time import sleep
console.setLevel('DEBUG')
ShutdownRequested=False
################################################################
# main loop
################################################################
while True:
try:
# shutdown logic
if not ShutdownRequested and GUI.stopped() and not GUI.is_alive():
logger.info('GUI triggered shutdown request')
# need to re-call SystemExit outside of the thread
sys.exit()
# wait around until it is time to tell GUI to stop
if GUI.is_alive():
if ShutdownRequested:
logger.error('threads did not shut down on their own, terminating them')
break
else:
# nothing to do
sleep(.1)
else:
if ShutdownRequested:
logger.debug('threads shut down on their own after being asked')
break
else:
logger.debug('threads shut down on their own without being asked')
break
except (KeyboardInterrupt, SystemExit):
logger.info('shutdown requested')
ShutdownRequested=True
logger.debug('shutting threads down')
GUI.stop()
# note: .join(20) returns after 20 seconds OR when the thread joins/quits, whichever is sooner.
# so, need to check .is_alive() above to see if the thread actually is still running.
GUI.join(20)
# now go up to (not GUI.is_alive()) and ShutdownRequested
logger.info('shutdown complete')