INNER CODE UNIT · Python
__init__
ok-oldking/ok-script · ok/ui/web/app.py:86
def __init__(self):
self._lock = threading.Lock()
self._active = {}
def register(self, session_key, wake):
token = object()
with self._lock:
previous = self._active.get(session_key)
self._active[session_key] = (token, wake)
if previous is not None:
previous[1]()
return token
def is_active(self, session_key, token):
with self._lock:
current = self._active.get(session_key)
return current is not None and current[0] is token