Inf*_*ner 9 python python-asyncio
我见过两种获取asyncio Lock 的方法:
async def main(lock):
async with lock:
async.sleep(100)
Run Code Online (Sandbox Code Playgroud)
和
async def main(lock):
with await lock:
async.sleep(100)
Run Code Online (Sandbox Code Playgroud)
它们之间有什么区别?
第二种形式with await lock自 Python 3.7 起已弃用,并在 Python 3.9 中删除。
使用 Python 3.7 运行它会给出以下警告:
DeprecationWarning: 'with await lock' 被弃用,使用'async with lock'代替
来源(滚动到底部):