Skip to content

concurrency

Classes

ThreadSaveCounter

A thread-safe counter, can be used in kiara modules to update completion percentage.

Source code in kiara/utils/concurrency.py
class ThreadSaveCounter(object):
    """A thread-safe counter, can be used in kiara modules to update completion percentage."""

    def __init__(self):

        self._current = 0
        self._lock = threading.Lock()

    @property
    def current(self):
        return self._current

    def current_percent(self, total: int) -> int:

        return int((self.current / total) * 100)

    def increment(self):

        with self._lock:
            self._current += 1
            return self._current

    def decrement(self):

        with self._lock:
            self._current -= 1
            return self._current
current property readonly
current_percent(self, total)
Source code in kiara/utils/concurrency.py
def current_percent(self, total: int) -> int:

    return int((self.current / total) * 100)
decrement(self)
Source code in kiara/utils/concurrency.py
def decrement(self):

    with self._lock:
        self._current -= 1
        return self._current
increment(self)
Source code in kiara/utils/concurrency.py
def increment(self):

    with self._lock:
        self._current += 1
        return self._current