mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 06:17:41 +00:00
Use _stop_event consistently across all threads as the way to signal that it should stop. Add thread joins with timeouts to allow the program to exit cleanly
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from threading import Event
|
||||
|
||||
import pytz
|
||||
|
||||
@@ -19,7 +20,7 @@ class SIGRefDataProvider:
|
||||
self.last_update_time = datetime.min.replace(tzinfo=pytz.UTC)
|
||||
self.status = "Not Started" if self.enabled else "Disabled"
|
||||
self.reference_count = 0
|
||||
self._stop = False
|
||||
self._stop_event = Event()
|
||||
|
||||
def start(self):
|
||||
"""Start the provider. This should return immediately after spawning threads to access the remote resources"""
|
||||
@@ -30,7 +31,7 @@ class SIGRefDataProvider:
|
||||
"""Stop any threads and prepare for application shutdown. Subclasses should implement this method and call
|
||||
super()."""
|
||||
|
||||
self._stop = True
|
||||
self._stop_event.set()
|
||||
|
||||
def _add_data(self, new_data):
|
||||
"""Add all the provided reference data objects to the data store."""
|
||||
@@ -43,7 +44,7 @@ class SIGRefDataProvider:
|
||||
# For the big data sources, loading will take a few minutes. If we want to shut down the software neatly
|
||||
# within the first few minutes of startup, we need a way to abort this expensive process of filling up the
|
||||
# disk cache.
|
||||
if self._stop:
|
||||
if self._stop_event.is_set():
|
||||
break
|
||||
|
||||
self.reference_count = len(new_data)
|
||||
|
||||
Reference in New Issue
Block a user