koclip / global_session.py
devtrent's picture
Global lock to avoid concurrent caching
98e7562
# Hacky way to provide global session.
import sys
GLOBAL_CONTAINER = sys
class GlobalState(object):
def __new__(cls, key="default"):
if not hasattr(GLOBAL_CONTAINER, '_global_states'):
GLOBAL_CONTAINER._global_states = {}
print("Global state container created")
if not GLOBAL_CONTAINER._global_states.get(key):
GLOBAL_CONTAINER._global_states[key] = super(GlobalState, cls).__new__(cls)
return GLOBAL_CONTAINER._global_states[key]