Skip to content

Commit

Permalink
Fixed task is created again when adding the task (#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidBySolo committed Jan 5, 2022
1 parent 18c6709 commit f0e30b1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions sanic/app.py
Expand Up @@ -1552,16 +1552,17 @@ def _loop_add_task(
name: Optional[str] = None,
register: bool = True,
) -> Task:
prepped = cls._prep_task(task, app, loop)
if sys.version_info == (3, 7):
if name:
error_logger.warning(
"Cannot set a name for a task when using Python 3.7. Your "
"task will be created without a name."
)
task = loop.create_task(prepped)
else:
task = loop.create_task(prepped, name=name)
if not isinstance(task, Future):
prepped = cls._prep_task(task, app, loop)
if sys.version_info == (3, 7):
if name:
error_logger.warning(
"Cannot set a name for a task when using Python 3.7. Your "
"task will be created without a name."
)
task = loop.create_task(prepped)
else:
task = loop.create_task(prepped, name=name)

if name and register:
app._task_registry[name] = task
Expand Down

0 comments on commit f0e30b1

Please sign in to comment.