[英]What is the cleanest way to test if a Python Task or Future has completed successfully?
测试 python Task
或Future
是否成功完成(既没有取消也没有失败)的最干净的方法是什么? 这是我想出的最好的:
success = future.done() and not future.cancelled() and future.exception() is None
而且它看起来很笨拙且容易出错,因为很容易忘记not future.cancelled()
。
它看起来对我很好。 如果您愿意,可以使用 function 包装:
def is_success(future):
return future.done() and not future.cancelled() and future.exception() is None
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.