【发布时间】:2019-03-03 04:34:49
【问题描述】:
这里有一段代码来自:https://github.com/ronf/asyncssh/blob/master/examples/math_server.py#L38
async def handle_client(process):
process.stdout.write('Enter numbers one per line, or EOF when done:\n')
total = 0
try:
async for line in process.stdin:
line = line.rstrip('\n')
if line:
try:
total += int(line)
except ValueError:
process.stderr.write('Invalid number: %s\n' % line)
except asyncssh.BreakReceived:
pass
在def 之前有一个async 关键字,但在for 循环之前也有一个关键字。在这里查看 asyncio 的文档时:https://docs.python.org/3/library/asyncio-task.html,我看不到这个 async 关键字的任何类似用途。
那么,关键字在这种情况下的作用是什么?
【问题讨论】:
-
这在PEP 492中有解释。
标签: python-asyncio