Code cleanup, make sure race conditions can't happen, at least in theory.

This commit is contained in:
Storm Dragon
2025-06-20 03:10:07 -04:00
parent f4ed8da4c3
commit 64e79f6945
3 changed files with 36 additions and 24 deletions

View File

@ -73,17 +73,20 @@ class driver(speechDriver):
return
self.clear_buffer()
self.lock.acquire(True)
if self.proc:
try:
self.proc.terminate()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.terminate():' + str(e),debug.debugLevel.WARNING)
try:
if self.proc:
try:
self.proc.kill()
self.proc.terminate()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.kill():' + str(e),debug.debugLevel.WARNING)
self.proc = None
self.lock.release()
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.terminate():' + str(e),debug.debugLevel.WARNING)
try:
self.proc.kill()
except Exception as e:
self.env['runtime']['debug'].writeDebugOut('speechDriver:Cancel:self.proc.kill():' + str(e),debug.debugLevel.WARNING)
self.proc = None
finally:
# Ensure lock is always released, even if process termination fails
self.lock.release()
def setCallback(self, callback):
print('SpeechDummyDriver: setCallback')