空港防疫算法交互
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
543B

  1. import asyncio
  2. import time
  3. async def task():
  4. print(f"{time.strftime('%H:%M:%S')} task 开始 ")
  5. time.sleep(2)
  6. print(f"{time.strftime('%H:%M:%S')} task 结束")
  7. coroutine = task()
  8. print(f"{time.strftime('%H:%M:%S')} 产生协程对象 {coroutine},函数并未被调用")
  9. loop = asyncio.get_event_loop()
  10. print(f"{time.strftime('%H:%M:%S')} 开始调用协程任务")
  11. start = time.time()
  12. loop.run_until_complete(coroutine)
  13. end = time.time()
  14. print(f"{time.strftime('%H:%M:%S')} 结束调用协程任务, 耗时{end - start} 秒")