mirror of
https://github.com/titanscouting/tra-superscript.git
synced 2024-11-12 22:26:18 +00:00
fixed key error in loop delay logic,
improved error logging to include stack trace
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
Former-commit-id: 3f32104c72
This commit is contained in:
parent
6f28e507a1
commit
1151541976
@ -160,6 +160,7 @@ import pymongo
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
@ -234,7 +235,6 @@ def main(send, verbose = False, profile = False, debug = False):
|
|||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
warnings.filterwarnings("ignore")
|
warnings.filterwarnings("ignore")
|
||||||
sys.stderr = open("errorlog.log", "w")
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
@ -315,7 +315,7 @@ def main(send, verbose = False, profile = False, debug = False):
|
|||||||
if profile:
|
if profile:
|
||||||
return # return instead of break to avoid sys.exit
|
return # return instead of break to avoid sys.exit
|
||||||
|
|
||||||
event_delay = config["event-delay"]
|
event_delay = config["variable"]["event-delay"]
|
||||||
if event_delay:
|
if event_delay:
|
||||||
send(stdout, INF, "loop delayed until database returns new matches")
|
send(stdout, INF, "loop delayed until database returns new matches")
|
||||||
new_match = False
|
new_match = False
|
||||||
@ -324,7 +324,7 @@ def main(send, verbose = False, profile = False, debug = False):
|
|||||||
new_match = check_new_database_matches(client, competition)
|
new_match = check_new_database_matches(client, competition)
|
||||||
send(stdout, INF, "database returned new matches")
|
send(stdout, INF, "database returned new matches")
|
||||||
else:
|
else:
|
||||||
loop_delay = float(config["loop-delay"])
|
loop_delay = float(config["variable"]["loop-delay"])
|
||||||
remaining_time = loop_delay - (time.time() - loop_start)
|
remaining_time = loop_delay - (time.time() - loop_start)
|
||||||
if remaining_time > 0:
|
if remaining_time > 0:
|
||||||
send(stdout, INF, "loop delayed by " + str(remaining_time) + " seconds")
|
send(stdout, INF, "loop delayed by " + str(remaining_time) + " seconds")
|
||||||
@ -334,17 +334,16 @@ def main(send, verbose = False, profile = False, debug = False):
|
|||||||
send(stdout, INF, "detected KeyboardInterrupt, killing threads")
|
send(stdout, INF, "detected KeyboardInterrupt, killing threads")
|
||||||
close_all()
|
close_all()
|
||||||
send(stdout, INF, "terminated threads, exiting")
|
send(stdout, INF, "terminated threads, exiting")
|
||||||
loop_exit_code = 0
|
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
send(stderr, ERR, "encountered an exception while running", code = 1)
|
send(stderr, ERR, "encountered an exception while running", code = 1)
|
||||||
print(e, file = stderr)
|
traceback.print_exc(file = stderr)
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
close_all()
|
close_all()
|
||||||
break
|
break
|
||||||
|
|
||||||
sys.exit(exit_code)
|
return exit_code
|
||||||
|
|
||||||
def parse_config_persistent(send, config):
|
def parse_config_persistent(send, config):
|
||||||
|
|
||||||
@ -520,19 +519,22 @@ def start(pid_path, verbose = False, profile = False, debug = False):
|
|||||||
import cProfile, pstats, io
|
import cProfile, pstats, io
|
||||||
profile = cProfile.Profile()
|
profile = cProfile.Profile()
|
||||||
profile.enable()
|
profile.enable()
|
||||||
main(send, profile = True)
|
exit_code = main(send, profile = True)
|
||||||
profile.disable()
|
profile.disable()
|
||||||
f = open("profile.txt", 'w+')
|
f = open("profile.txt", 'w+')
|
||||||
ps = pstats.Stats(profile, stream = f).sort_stats('cumtime')
|
ps = pstats.Stats(profile, stream = f).sort_stats('cumtime')
|
||||||
ps.print_stats()
|
ps.print_stats()
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
||||||
elif verbose:
|
elif verbose:
|
||||||
|
|
||||||
main(log, verbose = verbose)
|
exit_code = main(log, verbose = verbose)
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
||||||
elif debug:
|
elif debug:
|
||||||
|
|
||||||
main(log, verbose = True, profile = True, debug = debug)
|
exit_code = main(log, verbose = True, profile = True, debug = debug)
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
@ -571,7 +573,8 @@ def start(pid_path, verbose = False, profile = False, debug = False):
|
|||||||
asyncio.get_event_loop().run_until_complete(start_server)
|
asyncio.get_event_loop().run_until_complete(start_server)
|
||||||
threading.Thread(target = asyncio.get_event_loop().run_forever).start()
|
threading.Thread(target = asyncio.get_event_loop().run_forever).start()
|
||||||
|
|
||||||
main(send)
|
exit_code = main(send)
|
||||||
|
sys.exit(exit_code)
|
||||||
|
|
||||||
def stop(pid_path):
|
def stop(pid_path):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user