Python中的异步是什么?

Thy*_*st' 6 python asynchronous keyword python-3.x async-await

我读过关于新的Python"关键字" asyncawait.但它们既不是关键字,也不是命名空间中的保留.

>>> import keyword
>>> keyword.iskeyword("async")
False
>>> async
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'async' is not defined
Run Code Online (Sandbox Code Playgroud)

在我希望TrueSyntaxError关键字的示例中.

那么,asyncPython 到底是什么?这个怎么运作?

use*_*ica 7

出于向后兼容的目的,在Python 3.5和3.6中,asyncawait通过丑陋的tokenizer hack进行解析.内的async def功能定义,或用于async直接前一个def,标记生成器替换NAME为令牌asyncawaitASYNCAWAIT令牌; 在其他上下文中,标记化器NAME为它们发出常规标记,async并将await它们视为标识符.

您可以看到处理它的代码,Parser/tokenizer.c您可以在PEP 492中找到向后兼容性计划,介绍的PEP asyncawait语法.