Why does the task created by Sanic (using asyncio.create_task
) only print logs every 8 minutes, and can it be achieved to print in real-time?
server.py
# regular task
async def stuff_background_task(task_id='s1'):
if 'task_01' in app.config['SERVER_NO']:
task_name = multiprocessing.current_process().name
if task_name == 'Sanic-Server-0-0':
while True:
print('print log....') # output to terminal
await asyncio.sleep(10)
@app.listener('before_server_start')
async def setup_background_tasks(app, loop):
asyncio.create_task(stuff_background_task(task_id='s1'))