Skip to main content
 首页 » 编程设计

Python 3.4.3 asyncio 关键字 SyntaxError

2025年05月04日27lonelyxmas

终端输出值一千字,我猜

[~] $ python 
Python 3.4.3 (default, Jun 22 2016, 16:03:29) 
[GCC 4.9.3] on linux 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import asyncio 
>>> async def fun(): 
  File "<stdin>", line 1 
    async def fun(): 
            ^ 
SyntaxError: invalid syntax 

请您参考如下方法:

async 和 await 语法是在 Python 3.5 中引入的。 ( https://docs.python.org/3/reference/compound_stmts.html#coroutines )

在 Python 3.4 中,您需要使用 @asyncio.coroutine 装饰器和 yield from 语法。 ( https://docs.python.org/3.4/library/asyncio-task.html#coroutines )