Commit d5dc42f1 authored by Jonathan Michalon's avatar Jonathan Michalon

Print the traceback if something is raised during a ThreadPool run

Since we never reclaim finished tasks, exceptions raised during thread
run are never seen. Add a runner call in between to display them.
parent 234942a6
...@@ -12,6 +12,7 @@ import concurrent.futures ...@@ -12,6 +12,7 @@ import concurrent.futures
import signal import signal
import argparse import argparse
import logging import logging
import traceback
import sys import sys
import os import os
from time import sleep from time import sleep
...@@ -113,10 +114,10 @@ def run(): ...@@ -113,10 +114,10 @@ def run():
# do the actual polling # do the actual polling
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
if args.one:
def runner(check): def runner(check):
return check.run(immediate=True), check return check.run(immediate=True), check
if args.one:
futures = [] futures = []
for check in config.checks: for check in config.checks:
futures.append(executor.submit(runner, check)) futures.append(executor.submit(runner, check))
...@@ -129,10 +130,19 @@ def run(): ...@@ -129,10 +130,19 @@ def run():
print("Check %s failed:\n%s" % print("Check %s failed:\n%s" %
(str(check), check.errmsg.strip())) (str(check), check.errmsg.strip()))
else: else:
# Since we never reclaim finished tasks, exceptions raised during
# run are never seen. Using a runner we can at least display them.
def runner(check):
try:
return check.run()
except Exception as e:
traceback.print_exc()
raise e
# This will drift slowly as it takes (base_tick + espilon) seconds # This will drift slowly as it takes (base_tick + espilon) seconds
while True: while True:
for check in config.checks: for check in config.checks:
executor.submit(check.run) executor.submit(runner, check)
sleep(config.base_tick) sleep(config.base_tick)
mails.quit() mails.quit()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment