Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_or_create_stack(key):
t = asyncio.Task.current_task()
if not hasattr(t, key):
stack = TaskLocalManager()
setattr(t, key, stack)
else:
stack = getattr(t, key)
return stack