commit fafdb2753d5667357126ef107ff4b63ea74b1572 Author: Nicolas Duhamel Date: Mon Dec 28 11:40:54 2020 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c10d448 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + + +*.egg-info/ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1870a2e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2b0abc4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,12 @@ +[metadata] +name = citadel.utils +version = 0.0.1 + +[options] +package_dir = + =src +packages = find_namespace: + +[options.packages.find] +where = src + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a4f49f9 --- /dev/null +++ b/setup.py @@ -0,0 +1,2 @@ +import setuptools +setuptools.setup() diff --git a/src/citadel/utils/__init__.py b/src/citadel/utils/__init__.py new file mode 100644 index 0000000..d12d97a --- /dev/null +++ b/src/citadel/utils/__init__.py @@ -0,0 +1,20 @@ +import threading + +class TimeoutLock: + def __init__(self, interval: int): + self._interval = interval + self._locked = False + self._timer = None + + def lock(self): + self._locked = True + if self._timer is not None and self._timer.is_alive(): + self._timer.cancel() + self._timer = threading.Timer(self._interval, self._unlock).start() + + def _unlock(self): + self._locked = False + + @property + def is_locked(self): + return self._locked