def set_task_user(f):
 @functools.wraps(f)
 def wrapper(*args, **kw):
  old_user = get_user()
  set_user(get_task_user())
  try:
   result = f(*args, **kw)
  finally:
   set_user(old_user)
  return result
 return wrapper

def set_task_user ( f ) : @ functools . wraps ( f ) def wrapper ( * args , ** kw ) : old_user = get_user ( ) set_user ( get_task_user ( ) ) try : result = f ( * args , ** kw ) finally : set_user ( old_user ) return result return wrapper
sets the user to be the task user .