import threading
import requests
import time
async def task(task_id):
print("task %s thread %s begin" % (task_id, threading.current_thread().ident))
start = time.time()
try:
await requests.get('http//www.google.com', timeout=10)
except Exception as e:
pass
print("task %s thread %s end, spend %s " % (task_id, threading.current_thread().ident, int(time.time() - start)))
task(1)
task(2)
在python3中运行以上代码会出错,为什么?
python3 async_demo.py
async_demo.py:20:RuntimeWarning:从未等待协程'task' 任务(1)
async_demo.py:21:RuntimeWarning:从未等待协程'task' 任务(2)