Dont rely on global things in __del__

This commit is contained in:
Kovid Goyal 2022-07-17 13:33:22 +05:30
parent 1eb3bd675a
commit c74144140d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -7,7 +7,6 @@ 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
@ -53,11 +52,6 @@ qt.webenginecontext.info=false
overseers = []
def safe_wait(w, timeout):
with suppress(Exception):
return w.wait(timeout)
class Overseer:
def __init__(self):
@ -65,6 +59,12 @@ class Overseer:
self.workers = {}
overseers.append(weakref.ref(self))
def safe_wait(self, w, timeout):
try:
return w.wait(timeout)
except Exception:
pass
def worker_for_source(self, source):
wname = f'{source}::{get_ident()}'
with self.lock:
@ -96,10 +96,10 @@ class Overseer:
w.stdin.write(b'EXIT:0\n')
w.stdin.flush()
for w in self.workers.values():
if safe_wait(w, 0.2) is None:
if self.safe_wait(w, 0.2) is None:
w.terminate()
if not iswindows:
if safe_wait(w, 0.1) is None:
if self.safe_wait(w, 0.1) is None:
w.kill()
self.workers.clear()
close = __del__