Commit d5dab8a0 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

SIMAP Connector:

- Fixed TelemetryWorker wait loop granularity
parent 55053adf
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
# limitations under the License.


import logging, threading, time
import logging, math, threading, time
from typing import Optional
from simap_connector.service.simap_updater.SimapClient import SimapClient
from .Resources import Resources
@@ -22,6 +22,9 @@ from .Resources import Resources
LOGGER = logging.getLogger(__name__)


WAIT_LOOP_GRANULARITY = 0.5


class TelemetryWorker(threading.Thread):
    def __init__(
        self, worker_name : str, simap_client : SimapClient, resources : Resources,
@@ -54,11 +57,11 @@ class TelemetryWorker(threading.Thread):
                self._resources.generate_samples(self._simap_client)

                # Make wait responsible to terminations
                iterations = self._sampling_interval / 0.1
                iterations = int(math.ceil(self._sampling_interval / WAIT_LOOP_GRANULARITY))
                for _ in range(iterations):
                    if self._stop_event.is_set(): break
                    if self._terminate.is_set() : break
                    time.sleep(0.1)
                    time.sleep(WAIT_LOOP_GRANULARITY)

        except Exception:
            MSG = '[run][{:s}] Unhandled Exception'