Merge pull request #1066 from r0fls/1065

allow add_task after server starts
This commit is contained in:
Raphael Deem 2017-12-21 23:44:18 -08:00 committed by GitHub
commit 1a98e70281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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