protect the wave file switchover with a lock, since race conditions have

occured
This commit is contained in:
Jakob Ketterl 2019-07-10 22:09:31 +02:00
parent 2536d9f747
commit cb0b950d34
1 changed files with 5 additions and 0 deletions

View File

@ -17,6 +17,7 @@ class Ft8Chopper(threading.Thread):
def __init__(self, source):
self.source = source
(self.wavefilename, self.wavefile) = self.getWaveFile()
self.switchingLock = threading.Lock()
self.scheduler = sched.scheduler(time.time, time.sleep)
self.fileQueue = []
(self.outputReader, self.outputWriter) = Pipe()
@ -53,9 +54,11 @@ class Ft8Chopper(threading.Thread):
self.scheduler.enterabs(self.getNextDecodingTime(), 1, self.switchFiles)
def switchFiles(self):
self.switchingLock.acquire()
file = self.wavefile
filename = self.wavefilename
(self.wavefilename, self.wavefile) = self.getWaveFile()
self.switchingLock.release()
file.close()
self.fileQueue.append(filename)
@ -90,7 +93,9 @@ class Ft8Chopper(threading.Thread):
logger.warning("zero read on ft8 chopper")
self.doRun = False
else:
self.switchingLock.acquire()
self.wavefile.writeframes(data)
self.switchingLock.release()
self.decode()
logger.debug("FT8 chopper shutting down")