summaryrefslogtreecommitdiffstats
path: root/gamechest/utils.py
blob: adc55e7306f649dcca2f277147f8374ae5b0ee6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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