asyncio 系列四、asyncio 的异常

异常

官网连接:https://docs.python.org/zh-cn/3.7/library/asyncio-exceptions.html

 

exception asyncio.TimeoutError

该操作已超过规定的截止日期。

重要:这个异常与内置 TimeoutError 异常不同。

 

exception asyncio.CancelledError

该操作已被取消。

取消asyncio任务时,可以捕获此异常以执行自定义操作。在几乎所有情况下,都必须重新引发异常。

重要:此异常是 Exception 的子类,因此可能会被一个过于宽泛的 try..except 块意外地阻塞:

 

try:

    await operation

except Exception:

    # The cancellation is broken because the *except* block

    # suppresses the CancelledError exception.

    log.log('an error has occurred')

相反,应使用以下模式:

try:

    await operation

except asyncio.CancelledError:

    raise

except Exception:

    log.log('an error has occurred')

exception asyncio.InvalidStateError

 

Task 或 Future 的内部状态无效。

在为已设置结果值的未来对象设置结果值等情况下,可以引发此问题。

exception asyncio.SendfileNotAvailableError

"sendfile" 系统调用不适用于给定的套接字或文件类型。

子类 RuntimeError 。

 

exception asyncio.IncompleteReadError

请求的读取操作未完全完成。

由 asyncio stream APIs 提出

此异常是 EOFError 的子类。

 

expected

预期字节的总数( int )。

 

partial

到达流结束之前读取的 bytes 字符串。

 

exception asyncio.LimitOverrunError

在查找分隔符时达到缓冲区大小限制。

由 asyncio stream APIs 提出

 

consumed

要消耗的字节总数。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值