Skip to content

Sanic with task

代码

python
from sanic import Sanic
import asyncio

app = Sanic(__name__)

@app.add_task
async def my_background_task():
    while True:
        print("This task is running in the background")
        await asyncio.sleep(5)

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)