move the pump mechanism, allowing the old output code to be removed

This commit is contained in:
Jakob Ketterl 2021-09-20 15:09:26 +02:00
parent 4b36aca6fc
commit 9efe41a2b1
6 changed files with 29 additions and 81 deletions

View file

@ -29,6 +29,20 @@ class Module(BaseModule, metaclass=ABCMeta):
def getOutputFormat(self) -> Format:
pass
def pump(self, read, write):
def copy():
while True:
data = None
try:
data = read()
except ValueError:
pass
if data is None or isinstance(data, bytes) and len(data) == 0:
break
write(data)
return copy
class AutoStartModule(Module, metaclass=ABCMeta):
def _checkStart(self) -> None:
@ -47,20 +61,6 @@ class AutoStartModule(Module, metaclass=ABCMeta):
def start(self):
pass
def pump(self, read, write):
def copy():
while True:
data = None
try:
data = read()
except ValueError:
pass
if data is None or isinstance(data, bytes) and len(data) == 0:
break
write(data)
return copy
class ThreadModule(AutoStartModule, Thread, metaclass=ABCMeta):
def __init__(self):