mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont rely on global things in __del__
This commit is contained in:
parent
1eb3bd675a
commit
c74144140d
@ -7,7 +7,6 @@ import json
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import weakref
|
import weakref
|
||||||
from contextlib import suppress
|
|
||||||
from qt.core import QLoggingCategory, QUrl
|
from qt.core import QLoggingCategory, QUrl
|
||||||
from threading import Lock, Thread, get_ident
|
from threading import Lock, Thread, get_ident
|
||||||
|
|
||||||
@ -53,11 +52,6 @@ qt.webenginecontext.info=false
|
|||||||
overseers = []
|
overseers = []
|
||||||
|
|
||||||
|
|
||||||
def safe_wait(w, timeout):
|
|
||||||
with suppress(Exception):
|
|
||||||
return w.wait(timeout)
|
|
||||||
|
|
||||||
|
|
||||||
class Overseer:
|
class Overseer:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -65,6 +59,12 @@ class Overseer:
|
|||||||
self.workers = {}
|
self.workers = {}
|
||||||
overseers.append(weakref.ref(self))
|
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):
|
def worker_for_source(self, source):
|
||||||
wname = f'{source}::{get_ident()}'
|
wname = f'{source}::{get_ident()}'
|
||||||
with self.lock:
|
with self.lock:
|
||||||
@ -96,10 +96,10 @@ class Overseer:
|
|||||||
w.stdin.write(b'EXIT:0\n')
|
w.stdin.write(b'EXIT:0\n')
|
||||||
w.stdin.flush()
|
w.stdin.flush()
|
||||||
for w in self.workers.values():
|
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()
|
w.terminate()
|
||||||
if not iswindows:
|
if not iswindows:
|
||||||
if safe_wait(w, 0.1) is None:
|
if self.safe_wait(w, 0.1) is None:
|
||||||
w.kill()
|
w.kill()
|
||||||
self.workers.clear()
|
self.workers.clear()
|
||||||
close = __del__
|
close = __del__
|
||||||
|
Loading…
x
Reference in New Issue
Block a user