From 6f983ccb6b8b534bacab173913eda7accfccf821 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Wed, 18 Sep 2019 01:46:31 +0200 Subject: [PATCH] synchronize scheduler access --- owrx/wsjt.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/owrx/wsjt.py b/owrx/wsjt.py index 531c372..7b588ff 100644 --- a/owrx/wsjt.py +++ b/owrx/wsjt.py @@ -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()