synchronize scheduler access

This commit is contained in:
Jakob Ketterl 2019-09-18 01:46:31 +02:00
parent 3814767e28
commit 6f983ccb6b

View File

@ -90,6 +90,7 @@ class WsjtChopper(threading.Thread):
(self.wavefilename, self.wavefile) = self.getWaveFile()
self.switchingLock = threading.Lock()
self.scheduler = sched.scheduler(time.time, time.sleep)
self.schedulerLock = threading.Lock()
(self.outputReader, self.outputWriter) = Pipe()
self.doRun = True
super().__init__()
@ -118,11 +119,13 @@ class WsjtChopper(threading.Thread):
threading.Thread(target=self.scheduler.run).start()
def emptyScheduler(self):
for event in self.scheduler.queue:
self.scheduler.cancel(event)
with self.schedulerLock:
for event in self.scheduler.queue:
self.scheduler.cancel(event)
def _scheduleNextSwitch(self):
self.scheduler.enterabs(self.getNextDecodingTime(), 1, self.switchFiles)
with self.schedulerLock:
self.scheduler.enterabs(self.getNextDecodingTime(), 1, self.switchFiles)
def switchFiles(self):
self.switchingLock.acquire()