Browse Source

added pipfile

tanja 4 years ago
parent
commit
7c21d1f0aa
2 changed files with 79 additions and 0 deletions
  1. 38 0
      Pipfile
  2. 41 0
      cdplib/Singleton_Threadsafe.py

+ 38 - 0
Pipfile

@@ -0,0 +1,38 @@
+[[source]]
+name = "pypi"
+url = "https://pypi.org/simple"
+verify_ssl = true
+
+[dev-packages]
+
+[packages]
+# cdplib = {editable = true,git = "https://readonly:readonly@intra.acdp.at/gogs/tanja/cdplib.git"}
+pycodestyle = "*"
+ipykernel = "*"
+spyder-kernels = "==0.*"
+cloudpickle = "*"
+openpyxl = "*"
+setuptools = "*"
+scipy = "*"
+matplotlib = "*"
+tsfresh = "*"
+hyperopt = "*"
+xgboost = "*"
+scikit-learn = "*"
+pandas = "!=0.24.0"
+pandas-compat = "*"
+xmltodict = "*"
+sqlalchemy = "*"
+sqlparse = "*"
+pymysql = "*"
+xlrd = "*"
+pymongo = "*"
+jsonref = "*"
+faker = "*"
+xeger = "*"
+simplejson = "*"
+mysql = "*"
+sqlalchemy-utils = "*"
+
+[requires]
+python_version = "3"

+ 41 - 0
cdplib/Singleton_Threadsafe.py

@@ -0,0 +1,41 @@
+import functools
+import threading
+
+lock = threading.Lock()
+
+def synchronized(lock):
+    """ Synchronization decorator """
+    def wrapper(f):
+        @functools.wraps(f)
+        def inner_wrapper(*args, **kw):
+            with lock:
+                return f(*args, **kw)
+        return inner_wrapper
+    return wrapper
+
+class SingletonThreadsafe(type):
+    _instances = {}
+
+    def __call__(cls, *args, **kwargs):
+        if cls not in cls._instances:
+            cls._locked_call(*args, **kwargs)
+        return cls._instances[cls]
+
+    @synchronized(lock)
+    def _locked_call(cls, *args, **kwargs):
+        if cls not in cls._instances:
+            cls._instances[cls] = super(SingletonThreadsafe, cls).__call__(*args, **kwargs)
+
+
+class testClass(metaclass=SingletonThreadsafe):
+    pass
+    def __init__(self, message: str = None):
+        self._message = message 
+
+if __name__ == "__main__":
+    x = testClass('hello')
+    y = testClass('yellow')
+
+    print(x==y)
+    print(x._message)
+    print(y._message)