mirror of
https://github.com/jketterl/openwebrx.git
synced 2025-12-06 07:12:09 +01:00
switch out logreader with a buffer-based implementation (again)
This commit is contained in:
parent
e201ca07e3
commit
5058a91db0
|
|
@ -1,5 +1,5 @@
|
||||||
from pycsdr.modules import Module as BaseModule
|
from pycsdr.modules import Module as BaseModule
|
||||||
from pycsdr.modules import Reader, Writer, CallbackWriter
|
from pycsdr.modules import Reader, Writer, Buffer
|
||||||
from pycsdr.types import Format
|
from pycsdr.types import Format
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
@ -198,13 +198,20 @@ class PopenModule(AutoStartModule, metaclass=ABCMeta):
|
||||||
self.reader.stop()
|
self.reader.stop()
|
||||||
|
|
||||||
|
|
||||||
class LogWriter(CallbackWriter):
|
class LogReader(Thread):
|
||||||
def __init__(self, prefix: str):
|
def __init__(self, prefix: str, buffer: Buffer):
|
||||||
|
self.reader = buffer.getReader()
|
||||||
self.logger = logging.getLogger(prefix)
|
self.logger = logging.getLogger(prefix)
|
||||||
self.retained = bytes()
|
self.retained = bytes()
|
||||||
super().__init__(Format.CHAR)
|
super().__init__()
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def run(self) -> None:
|
||||||
|
while True:
|
||||||
|
data = self.reader.read()
|
||||||
|
if data is None:
|
||||||
|
return
|
||||||
|
|
||||||
def write(self, data: memoryview) -> None:
|
|
||||||
self.retained += data
|
self.retained += data
|
||||||
lines = self.retained.split(b"\n")
|
lines = self.retained.split(b"\n")
|
||||||
|
|
||||||
|
|
@ -216,3 +223,6 @@ class LogWriter(CallbackWriter):
|
||||||
# log all completed lines
|
# log all completed lines
|
||||||
for line in lines[0:-1]:
|
for line in lines[0:-1]:
|
||||||
self.logger.info("{}: {}".format("STDOUT", line.strip(b'\n').decode()))
|
self.logger.info("{}: {}".format("STDOUT", line.strip(b'\n').decode()))
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.reader.stop()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from pycsdr.types import Format
|
from pycsdr.types import Format
|
||||||
from pycsdr.modules import Writer, TcpSource, ExecModule
|
from pycsdr.modules import Writer, TcpSource, ExecModule, Buffer
|
||||||
from csdr.module import LogWriter
|
from csdr.module import LogReader
|
||||||
from owrx.config.core import CoreConfig
|
from owrx.config.core import CoreConfig
|
||||||
from owrx.config import Config
|
from owrx.config import Config
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
@ -160,7 +160,9 @@ class DirewolfModule(ExecModule, DirewolfConfigSubscriber):
|
||||||
super().__init__(Format.SHORT, Format.CHAR, ["direwolf", "-c", self.direwolfConfigPath, "-r", "48000", "-t", "0", "-q", "d", "-q", "h"])
|
super().__init__(Format.SHORT, Format.CHAR, ["direwolf", "-c", self.direwolfConfigPath, "-r", "48000", "-t", "0", "-q", "d", "-q", "h"])
|
||||||
# direwolf supplies the data via a socket which we tap into in start()
|
# direwolf supplies the data via a socket which we tap into in start()
|
||||||
# the output on its STDOUT is informative, but we still want to log it
|
# the output on its STDOUT is informative, but we still want to log it
|
||||||
super().setWriter(LogWriter(__name__))
|
buffer = Buffer(Format.CHAR)
|
||||||
|
self.logReader = LogReader(__name__, buffer)
|
||||||
|
super().setWriter(buffer)
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def __writeConfig(self):
|
def __writeConfig(self):
|
||||||
|
|
@ -199,6 +201,8 @@ class DirewolfModule(ExecModule, DirewolfConfigSubscriber):
|
||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
super().stop()
|
super().stop()
|
||||||
|
self.logReader.stop()
|
||||||
|
self.logReader = None
|
||||||
os.unlink(self.direwolfConfigPath)
|
os.unlink(self.direwolfConfigPath)
|
||||||
self.direwolfConfig.unwire(self)
|
self.direwolfConfig.unwire(self)
|
||||||
self.direwolfConfig = None
|
self.direwolfConfig = None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue