pass through all kwargs from BSCache to bsread.source

This commit is contained in:
2025-02-11 11:48:34 +01:00
parent 047a0c2478
commit ab2a77e4d7

View File

@ -1,5 +1,6 @@
from time import sleep
from bsread import source, dispatcher from bsread import source, dispatcher
from bsread import BIND, CONNECT, PUSH, PULL, PUB, SUB # make these easier to access
from .bsvar import BSVar from .bsvar import BSVar
from .prodthread import ProdThread from .prodthread import ProdThread
@ -12,9 +13,10 @@ FIXED_CHANNELS = {
class BSCache: class BSCache:
def __init__(self, timeout=1000, maxsize=100): def __init__(self, maxsize=100, **kwargs):
self.timeout = timeout kwargs.setdefault("receive_timeout", 1000)
self.channels = {} self.channels = kwargs.pop("channels", {})
self.kwargs = kwargs
self.data = None self.data = None
self.pt = ProdThread(self.run, maxsize=maxsize) self.pt = ProdThread(self.run, maxsize=maxsize)
@ -34,7 +36,7 @@ class BSCache:
def run(self, running): def run(self, running):
timeout_counter = 0 timeout_counter = 0
configs = self.channels.values() configs = self.channels.values()
with source(channels=configs, receive_timeout=self.timeout) as src: with source(channels=configs, **self.kwargs) as src:
while running.is_set(): while running.is_set():
msg = src.receive() msg = src.receive()
if msg is None: if msg is None: