Python 3.4.3 asyncio关键字SyntaxError

时间:2016-07-08 15:37:57

标签: python python-asyncio

终端输出值千言万语,我想

[~] $ 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

2 个答案:

答案 0 :(得分:4)

Python 3.5中引入了asyncawait语法。 (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

答案 1 :(得分:1)

在Python 3.5中添加了async关键字。