summaryrefslogtreecommitdiffstats
path: root/gamechest/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'gamechest/utils.py')
-rw-r--r--gamechest/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gamechest/utils.py b/gamechest/utils.py
new file mode 100644
index 0000000..adc55e7
--- /dev/null
+++ b/gamechest/utils.py
@@ -0,0 +1,19 @@
+#!python3
+
+import threading
+
+class LockedData:
+ 'every attribute access to this class is locked except lock and data'
+
+ def __init__(self, data={}):
+ super().__setattr__('lock', threading.Lock())
+ super().__setattr__('data', dict())
+ self.data.update(data)
+
+ def __getattr__(self, name):
+ with self.lock:
+ return self.data[name]
+
+ def __setattr__(self, name, value):
+ with self.lock:
+ self.data[name] = value