allow to set timeout and maxsize; fixed a weird conditional
This commit is contained in:
@ -6,10 +6,11 @@ from .prodthread import ProdThread
|
||||
|
||||
class BSCache:
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, timeout=1000, maxsize=100):
|
||||
self.timeout = timeout
|
||||
self.channels = {}
|
||||
self.data = None
|
||||
self.pt = ProdThread(self.run)
|
||||
self.pt = ProdThread(self.run, maxsize=maxsize)
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.data)
|
||||
@ -26,9 +27,11 @@ class BSCache:
|
||||
|
||||
def run(self, running):
|
||||
configs = self.channels.values()
|
||||
with source(channels=configs, receive_timeout=-1) as src:
|
||||
with source(channels=configs, receive_timeout=self.timeout) as src:
|
||||
while running.is_set():
|
||||
msg = src.receive()
|
||||
if msg is None:
|
||||
continue
|
||||
data = repack(msg)
|
||||
if data:
|
||||
yield data
|
||||
@ -39,7 +42,7 @@ class BSCache:
|
||||
|
||||
|
||||
def get_var(self, name, modulo=None, offset=None):
|
||||
if name is not "pid" and not name in self.channels:
|
||||
if name != "pid" and name not in self.channels:
|
||||
if not is_available(name):
|
||||
raise ValueError(f"channel {name} is not available")
|
||||
cfg = make_channel_config(name, modulo, offset)
|
||||
|
Reference in New Issue
Block a user