【问题标题】:Will `async with` containing multiple statements execute them synchronously?包含多个语句的“async with”会同步执行它们吗?
【发布时间】:2021-11-28 15:47:08
【问题描述】:

我正在使用aiosqlite 库,想知道下面的代码是按顺序执行插入还是异步执行?

async with (
    db.execute("INSERT ..."),
    db.execute("INSERT ..."),
):
    pass

我猜的顺序?

【问题讨论】:

  • 嗯...是的,是哪一个? :)
  • async with 等待每个上下文管理器的__aenter__ 方法,因此它会按顺序处理它们。

标签: python sql asynchronous async-await with-statement


【解决方案1】:

根据Barmar's的评论,它们确实会按顺序执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多