Sanic 类的add_task()方法的API接口。
add_task()方法/函数
定义
add_task(task)
在循环开始后安排任务稍后运行。 与asyncio.ensure_future
的不同之处在于它不会返回future,并且实际的ensure_future调用会延迟到服务器启动之前。
参数
- task:Future,协程或可等待变量。
例子:
import asyncio
from sanic import Sanic
app = Sanic()
async def notify_server_started_after_five_seconds():
await asyncio.sleep(5)
print('Server successfully started!')
app.add_task(notify_server_started_after_five_seconds())
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)

我的公众号:猿人学 Python 上会分享更多心得体会,敬请关注。
***版权申明:若没有特殊说明,文章皆是猿人学 yuanrenxue.con 原创,没有猿人学授权,请勿以任何形式转载。***
说点什么吧...