mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Workaround for SSIPClient using non-daemonic thread and therefore hanging interpreter shutdown
This commit is contained in:
parent
1cacc7484a
commit
85bf7f823e
@ -9,5 +9,5 @@ if iswindows:
|
||||
elif ismacos:
|
||||
pass
|
||||
else:
|
||||
from .linux import speak_simple_text
|
||||
speak_simple_text
|
||||
from .linux import Client
|
||||
Client
|
||||
|
@ -2,29 +2,30 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import atexit
|
||||
from .errors import TTSSystemUnavailable
|
||||
|
||||
|
||||
def get_client():
|
||||
client = getattr(get_client, 'ans', None)
|
||||
if client is not None:
|
||||
return client
|
||||
from speechd.client import SSIPClient, SpawnError
|
||||
try:
|
||||
client = get_client.ans = SSIPClient('calibre')
|
||||
except SpawnError as err:
|
||||
raise TTSSystemUnavailable(_('Could not find speech-dispatcher on your system. Please install it.'), str(err))
|
||||
atexit.register(client.close)
|
||||
return client
|
||||
class Client:
|
||||
|
||||
def __init__(self):
|
||||
self.create_ssip_client()
|
||||
|
||||
def speak_simple_text(text):
|
||||
client = get_client()
|
||||
from speechd.client import SSIPCommunicationError
|
||||
try:
|
||||
client.speak(text)
|
||||
except SSIPCommunicationError:
|
||||
get_client.ans = None
|
||||
client = get_client()
|
||||
client.speak(text)
|
||||
def create_ssip_client(self):
|
||||
from speechd.client import SSIPClient, SpawnError
|
||||
try:
|
||||
self.ssip_client = SSIPClient('calibre')
|
||||
except SpawnError as err:
|
||||
raise TTSSystemUnavailable(_('Could not find speech-dispatcher on your system. Please install it.'), str(err))
|
||||
|
||||
def __del__(self):
|
||||
self.ssip_client.close()
|
||||
del self.ssip_client
|
||||
|
||||
def speak_simple_text(self, text):
|
||||
from speechd.client import SSIPCommunicationError
|
||||
try:
|
||||
self.ssip_client.speak(text)
|
||||
except SSIPCommunicationError:
|
||||
self.ssip_client.close()
|
||||
self.create_ssip_client()
|
||||
self.ssip_client.speak(text)
|
||||
|
@ -674,6 +674,7 @@ class EbookViewer(MainWindow):
|
||||
return
|
||||
self.shutting_down = True
|
||||
self.search_widget.shutdown()
|
||||
self.web_view.shutdown()
|
||||
try:
|
||||
self.save_state()
|
||||
self.save_annotations()
|
||||
|
@ -467,6 +467,7 @@ class WebView(RestartingWebEngineView):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
self._host_widget = None
|
||||
self._tts_client = None
|
||||
self.callback_id_counter = count()
|
||||
self.callback_map = {}
|
||||
self.current_cfi = self.current_content_file = None
|
||||
@ -529,9 +530,18 @@ class WebView(RestartingWebEngineView):
|
||||
self.inspector = Inspector(parent.inspector_dock.toggleViewAction(), self)
|
||||
parent.inspector_dock.setWidget(self.inspector)
|
||||
|
||||
@property
|
||||
def tts_client(self):
|
||||
if self._tts_client is None:
|
||||
from calibre.gui2.tts.implementation import Client
|
||||
self._tts_client = Client()
|
||||
return self._tts_client
|
||||
|
||||
def speak_simple_text(self, text):
|
||||
from calibre.gui2.tts.implementation import speak_simple_text
|
||||
speak_simple_text(text)
|
||||
self.tts_client.speak_simple_text(text)
|
||||
|
||||
def shutdown(self):
|
||||
self._tts_client = None
|
||||
|
||||
def set_shortcut_map(self, smap):
|
||||
self.shortcut_map = smap
|
||||
|
Loading…
x
Reference in New Issue
Block a user