Skip to content

Commit

Permalink
Avoid errors on disconnecting handler that writes to a closed pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarddeR committed Aug 2, 2023
1 parent 5a87149 commit 81197f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions addon/globalPlugins/rdAccess/handlers/remoteBrailleHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
from brailleViewer import postBrailleViewerToolToggledAction
import versionInfo
from logHandler import log

if typing.TYPE_CHECKING:
from ....lib import protocol
Expand Down Expand Up @@ -99,8 +100,11 @@ def _handleExecuteGesture(self, gesture):
kwargs['dots'] = gesture.dots
kwargs['space'] = gesture.space
newGesture = protocol.braille.BrailleInputGesture(**kwargs)
self.writeMessage(protocol.BrailleCommand.EXECUTE_GESTURE, self._pickle(newGesture))
return False
try:
self.writeMessage(protocol.BrailleCommand.EXECUTE_GESTURE, self._pickle(newGesture))
return False
except WindowsError:
log.warning("Error calling _handleExecuteGesture", exc_info=True)
return True

def _handleBrailleHandlerEnabled(self):
Expand Down
12 changes: 10 additions & 2 deletions addon/globalPlugins/rdAccess/handlers/remoteSpeechHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tones
import nvwave
from hwIo.ioThread import IoThread
from logHandler import log

if typing.TYPE_CHECKING:
from ....lib import protocol
Expand Down Expand Up @@ -95,13 +96,20 @@ def _onSynthIndexReached(
byteorder=sys.byteorder, # for a single byte big/little endian does not matter.
signed=False
)
self.writeMessage(protocol.SpeechCommand.INDEX_REACHED, indexBytes)
try:
self.writeMessage(protocol.SpeechCommand.INDEX_REACHED, indexBytes)
except WindowsError:
log.warning("Error calling _onSynthIndexReached", exc_info=True)
self._indexesSpeaking.remove(index)

def _onSynthDoneSpeaking(self, synth: typing.Optional[synthDriverHandler.SynthDriver] = None):
assert synth == self._driver
if len(self._indexesSpeaking) > 0:
self._indexesSpeaking.clear()
self.writeMessage(protocol.SpeechCommand.INDEX_REACHED, b'\x00\x00')
try:
self.writeMessage(protocol.SpeechCommand.INDEX_REACHED, b'\x00\x00')
except WindowsError:
log.warning("Error calling _onSynthDoneSpeaking", exc_info=True)

def _handleDriverChanged(self, synth: synthDriverHandler.SynthDriver):
self._indexesSpeaking.clear()
Expand Down

0 comments on commit 81197f7

Please sign in to comment.