From c2428b3d099424e85195a00a4f6b25dd95114a62 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 21 Apr 2022 14:08:53 +0530 Subject: [PATCH] Fix errors in __del__ of overseer I can never get used to be absurd python stdlib philosophy of raising timeouterrors on wait instead of returning None --- src/calibre/scraper/simple.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/scraper/simple.py b/src/calibre/scraper/simple.py index ec070cc514..d00d598b4c 100644 --- a/src/calibre/scraper/simple.py +++ b/src/calibre/scraper/simple.py @@ -7,6 +7,7 @@ import json import os import sys import weakref +from contextlib import suppress from qt.core import QLoggingCategory, QUrl from threading import Lock, Thread, get_ident @@ -52,6 +53,11 @@ qt.webenginecontext.info=false overseers = [] +def safe_wait(w, timeout): + with suppress(Exception): + return w.wait(timeout) + + class Overseer: def __init__(self): @@ -90,10 +96,10 @@ class Overseer: w.stdin.write(b'EXIT:0\n') w.stdin.flush() for w in self.workers.values(): - if w.wait(0.2) is None: + if safe_wait(w, 0.2) is None: w.terminate() if not iswindows: - if w.wait(0.1) is None: + if safe_wait(w, 0.1) is None: w.kill() self.workers.clear() close = __del__