commit c6078004b44541b8c7c1960ccc9c26751837fb98 Author: juga0 juga@riseup.net Date: Tue Jan 8 15:38:05 2019 +0000
resultdump: use global end event
instead of assigning it to the ResultDump object. --- sbws/lib/resultdump.py | 10 ++++------ tests/integration/lib/test_relayprioritizer.py | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/sbws/lib/resultdump.py b/sbws/lib/resultdump.py index 52a0b7c..6f80c2d 100644 --- a/sbws/lib/resultdump.py +++ b/sbws/lib/resultdump.py @@ -4,7 +4,6 @@ import time import logging from glob import glob from threading import Thread -from threading import Event from threading import RLock from queue import Queue from queue import Empty @@ -14,6 +13,7 @@ from enum import Enum from sbws.globals import RESULT_VERSION, fail_hard from sbws.util.filelock import DirectoryLock from sbws.lib.relaylist import Relay +from .. import settings
log = logging.getLogger(__name__)
@@ -527,13 +527,11 @@ class ResultSuccess(Result): class ResultDump: ''' Runs the enter() method in a new thread and collects new Results on its queue. Writes them to daily result files in the data directory ''' - def __init__(self, args, conf, end_event): + def __init__(self, args, conf): assert os.path.isdir(conf.getpath('paths', 'datadir')) - assert isinstance(end_event, Event) self.conf = conf self.fresh_days = conf.getint('general', 'data_period') self.datadir = conf.getpath('paths', 'datadir') - self.end_event = end_event self.data = {} self.data_lock = RLock() self.thread = Thread(target=self.enter) @@ -563,7 +561,7 @@ class ResultDump: assert isinstance(result, Result) fp = result.fingerprint nick = result.nickname - if isinstance(result, ResultError) and self.end_event.is_set(): + if isinstance(result, ResultError) and settings.end_event.is_set(): log.debug('Ignoring %s for %s %s because we are shutting down', type(result).__name__, nick, fp) return @@ -586,7 +584,7 @@ class ResultDump: with self.data_lock: self.data = load_recent_results_in_datadir( self.fresh_days, self.datadir) - while not (self.end_event.is_set() and self.queue.empty()): + while not (settings.end_event.is_set() and self.queue.empty()): try: event = self.queue.get(timeout=1) except Empty: diff --git a/tests/integration/lib/test_relayprioritizer.py b/tests/integration/lib/test_relayprioritizer.py index d5464b8..76c5969 100644 --- a/tests/integration/lib/test_relayprioritizer.py +++ b/tests/integration/lib/test_relayprioritizer.py @@ -1,9 +1,10 @@ from sbws.lib.resultdump import ResultDump from sbws.lib.resultdump import ResultSuccess, ResultErrorCircuit from sbws.lib.relayprioritizer import RelayPrioritizer -from threading import Event from unittest.mock import patch
+from sbws import settings +
def static_time(value): while True: @@ -41,8 +42,7 @@ def test_relayprioritizer_general(time_mock, sbwshome_empty, args, persistent_launch_tor): now = 1000000 time_mock.side_effect = static_time(now) - end_event = Event() - rd = ResultDump(args, conf, end_event) + rd = ResultDump(args, conf) try: rp = RelayPrioritizer(args, conf, rl, rd) results = [] @@ -66,4 +66,4 @@ def test_relayprioritizer_general(time_mock, sbwshome_empty, args, relay = best_list[pos] assert relay.nickname == nick finally: - end_event.set() + settings.end_event.set()