【发布时间】:2020-11-11 14:04:14
【问题描述】:
我目前正在使用 python 3.7.x 开发 asyncio,不确定确切的版本,现在我正在尝试安排一个任务。而且我无法获得输出,即使永远运行这个东西。这是我目前拥有的代码
import asyncio
async def print_now():
print("Hi there")
loop = asyncio.get_event_loop()
loop.call_later(print_now())
loop.run_until_complete(asyncio.sleep(1))
这会产生以下错误:
Traceback (most recent call last):
File "D:\Coding\python\async\main.py", line 7, in <module>
loop.call_later(print_now())
TypeError: call_later() missing 1 required positional argument: 'callback'
call_later() 中的回电是print_now 我只试过print_now 和print_now()
我也尝试过使用loop.run_forever() 而不是loop.run_until_complete() ,到目前为止我什么也没得到
有时我没有得到任何输出或其他错误。
【问题讨论】:
-
您是否阅读了错误消息和how
call_laterworks...? -
查看call_later 的文档。您缺少一个参数。
标签: python python-3.x python-asyncio