-
Notifications
You must be signed in to change notification settings - Fork 0
/
RC
executable file
·64 lines (49 loc) · 2.05 KB
/
RC
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
#!/usr/bin/python3
# License GPL 2. Copyright Paul D. Gilbert, 2017, 2018
"""
Run by race committee to set the course and distribute to racing boats.
This program needs PYTHONPATH setting to find other modules, e.g.
export PYTHONPATH=/path/to/Vcourse/lib
Configuration for the local course setup is read from RCconfig.
Configuration for the computer GPS setup is read from GPSconfig.
A GUI is opened for setting a course and distributing to racing boats.
"""
import threading
import signal
import logging
import time
import tkinter
import sys
import distribution
import RCmanagement
logFormat ='(%(threadName)-9s) %(message)s'
#logging.basicConfig(level=logging.DEBUG, format=logFormat,)
logging.basicConfig(level=logging.INFO, format=logFormat,)
if __name__ == '__main__':
logging.info('main thread starting. ' +time.strftime('%Y-%m-%d %H:%M:%S %Z'))
shutdown = threading.Event()
dr = distribution.distributer(shutdown)
dr.start()
race = tkinter.Tk()
RCmanagement.initiate()
z = RCmanagement.RCmanager(race, dr)
def abortHandler(signum, frame):
logging.debug('main thread abortHandler setting shutdown signal.')
shutdown.set() # to exit threads
time.sleep(5) # wait as long as socket timeout in distributionHandler
logging.info('main thread exit via abortHandler. ' +time.strftime('%Y-%m-%d %H:%M:%S %Z')+ '\n')
logging.debug('threads running: ')
logging.debug(threading.enumerate())
sys.exit("RC process killed.")
# ^C works if process is not deamonized with &
signal.signal(signal.SIGINT, abortHandler) # ^C, kill -2
signal.signal(signal.SIGTERM, abortHandler) # kill -15 (default)
logging.debug(threading.enumerate())
race.mainloop()
logging.debug('main thread setting shutdown signal.')
shutdown.set() # to exit threads
time.sleep(5) # wait as long as socket timeout in distributionHandler
logging.info('main thread exit via end. ' +time.strftime('%Y-%m-%d %H:%M:%S %Z')+ '\n')
logging.debug('threads running: ')
logging.debug(threading.enumerate())
sys.exit()