import threading # --------------------------------------------------------------------------- # Thread-local storage for current user # --------------------------------------------------------------------------- _local = threading.local() # --------------------------------------------------------------------------- # set_current_user() # --------------------------------------------------------------------------- def set_current_user(user): """Store the current user in thread-local storage.""" _local.user = user # --------------------------------------------------------------------------- # get_current_user() # --------------------------------------------------------------------------- def get_current_user(): """Retrieve the current user from thread-local storage (or None).""" return getattr(_local, "user", None)