in context.py [0:0]
def create_task(*args, **kwargs) -> asyncio.Task:
"""Creates a task that uses the context TaskGroup.
If no context is available then `asyncio.create_task` will be used.
Args:
*args: Positional arguments to pass to `asyncio.create_task`.
**kwargs: Keyword arguments to pass to `asyncio.create_task`.
Returns:
An asyncio task.
"""
tg = task_group()
if tg is None:
task = asyncio.create_task(*args, **kwargs)
_without_context_background_tasks.add(task)
task.add_done_callback(_without_context_background_tasks.discard)
return task
return tg.create_task(*args, **kwargs)