python asyncio 任务应该总是 return 什么吗?
should python asyncio task always return something?
这听起来像是一个愚蠢的问题,但我找不到明确的答案。
I can read, in the asyncio doc here:
done()
Return True if the Task is done.
A Task is done when the wrapped coroutine either returned a value, raised an exception, or the Task was cancelled.
这是否意味着无论我创建什么协程,它都必须总是 return 某些东西,而不是在工作完成时简单地结束??
如果是,最 pythonic 的方法是什么?
return 0
或 return None
?
所有 python 功能 return None
如果未明确提供 return 值,则完成后,您无需明确 return 任何内容。如果你需要提前 return 你可以只使用 return
而不使用任何等价于 return None
.
的值
这听起来像是一个愚蠢的问题,但我找不到明确的答案。
I can read, in the asyncio doc here:
done()
Return True if the Task is done.A Task is done when the wrapped coroutine either returned a value, raised an exception, or the Task was cancelled.
这是否意味着无论我创建什么协程,它都必须总是 return 某些东西,而不是在工作完成时简单地结束??
如果是,最 pythonic 的方法是什么?
return 0
或 return None
?
所有 python 功能 return None
如果未明确提供 return 值,则完成后,您无需明确 return 任何内容。如果你需要提前 return 你可以只使用 return
而不使用任何等价于 return None
.