Remove the ThreadsManager.terminating flag

This commit is contained in:
allegroai 2022-09-29 19:23:26 +03:00
parent 98ed3075dd
commit 3ae410a1e9
7 changed files with 7 additions and 11 deletions

View File

@ -288,7 +288,7 @@ class MetricsRefresher:
queue_metrics = QueueBLL().metrics
sleep(10)
while not ThreadsManager.terminating:
while True:
try:
for queue in Queue.objects():
timestamp = es_factory.get_timestamp_millis()

View File

@ -71,7 +71,7 @@ class ResourceMonitor:
@classmethod
@stat_threads.register("resource_monitor", daemon=True)
def start(cls):
while not ThreadsManager.terminating:
while True:
sleep(cls.sample_interval_sec)
sample = Sample.get_current_sample()
with cls._lock:

View File

@ -21,7 +21,6 @@ from apiserver.database.model.queue import Queue
from apiserver.database.model.task.task import Task
from apiserver.tools import safe_get
from apiserver.utilities.json import dumps
from apiserver.utilities.threads_manager import ThreadsManager
from apiserver.version import __version__ as current_version
from .resource_monitor import ResourceMonitor, stat_threads
@ -56,7 +55,7 @@ class StatisticsReporter:
hours=config.get("apiserver.statistics.report_interval_hours", 24)
)
sleep(report_interval.total_seconds())
while not ThreadsManager.terminating:
while True:
try:
for company in Company.objects(
defaults__stats_option__enabled=True
@ -87,7 +86,7 @@ class StatisticsReporter:
WarningFilter.attach()
while not ThreadsManager.terminating:
while True:
try:
report = cls.send_queue.get()

View File

@ -39,7 +39,7 @@ class NonResponsiveTasksWatchdog:
@threads.register("non_responsive_tasks_watchdog", daemon=True)
def start(cls):
sleep(cls.settings.watch_interval_sec)
while not ThreadsManager.terminating:
while True:
watch_interval = cls.settings.watch_interval_sec
if cls.settings.enabled:
try:

View File

@ -28,7 +28,6 @@ from apiserver.service_repo import ServiceRepo
from apiserver.sync import distributed_lock
from apiserver.updates import check_updates_thread
from apiserver.utilities.env import get_bool
from apiserver.utilities.threads_manager import ThreadsManager
log = config.logger(__file__)
@ -125,4 +124,4 @@ class AppSequence:
NonResponsiveTasksWatchdog.start()
def _on_worker_stop(self):
ThreadsManager.terminating = True
pass

View File

@ -12,7 +12,6 @@ from apiserver.config_repo import config
from apiserver.config.info import get_version
from apiserver.database.model.settings import Settings
from apiserver.redis_manager import redman
from apiserver.utilities.threads_manager import ThreadsManager
log = config.logger(__name__)
@ -99,7 +98,7 @@ class CheckUpdatesThread(Thread):
)
def _check_updates(self):
while not ThreadsManager.terminating:
while True:
# noinspection PyBroadException
try:
if self._redis.set(

View File

@ -7,7 +7,6 @@ class ThreadsManager:
objects = {}
lock = Lock()
request_context_creator: ClassVar[Callable] = None
terminating: ClassVar[bool] = False
def __init__(self, name=None):
self.name = name or self.__class__.__name__