Python asyncio.sleep SyntaxError

Sit*_*iri 1 python syntax-error python-3.x python-asyncio

我究竟做错了什么?当我跑这个,

import asyncio
def oneSecond():
    await asyncio.sleep(1)
Run Code Online (Sandbox Code Playgroud)

我明白了:

File "<string>", line 3
await asyncio.sleep(1)
            ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

使用Python 3.3

Kla*_* D. 6

您在awaitPython 3.3 中使用了该关键字,但在3.5版之前尚未将其添加到Python中.你应该升级你的Python版本.

此外,您还必须将您的功能定义为async:

async def oneSecond():
    await asyncio.sleep(1)
Run Code Online (Sandbox Code Playgroud)