为什么出现错误“协程'任务'从未等待”?

时间:2018-06-29 10:00:38

标签: python-3.x async-await

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)

0 个答案:

没有答案