allow add_task after server starts

This commit is contained in:
Raphael Deem 2017-12-21 23:27:34 -08:00
parent 04b04f094c
commit 8e3f3977bd

View File

@ -86,12 +86,18 @@ class Sanic:
:param task: future, couroutine or awaitable :param task: future, couroutine or awaitable
""" """
@self.listener('before_server_start') try:
def run(app, loop):
if callable(task): if callable(task):
loop.create_task(task()) self.loop.create_task(task())
else: else:
loop.create_task(task) self.loop.create_task(task)
except SanicException:
@self.listener('before_server_start')
def run(app, loop):
if callable(task):
loop.create_task(task())
else:
loop.create_task(task)
# Decorator # Decorator
def listener(self, event): def listener(self, event):