最終更新:2021-07-30 (金) 17:14:42 (1000d)  

Python/async with
Top / Python / async with

構文

  • async with EXPR as VAR:
        BLOCK

等価

  • mgr = (EXPR)
    aexit = type(mgr).__aexit__
    aenter = type(mgr).__aenter__(mgr)
    
    VAR = await aenter
    try:
        BLOCK
    except:
        if not await aexit(mgr, *sys.exc_info()):
            raise
    else:
        await aexit(mgr, None, None, None)

関連

  • async for?