avoid duplicate method

This commit is contained in:
Jakob Ketterl 2021-09-15 15:01:36 +02:00
parent 1ff3c174c2
commit 6129b92277
2 changed files with 14 additions and 28 deletions

View File

@ -47,6 +47,20 @@ class AutoStartModule(Module, metaclass=ABCMeta):
def start(self): def start(self):
pass 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): class ThreadModule(AutoStartModule, Thread, metaclass=ABCMeta):
def __init__(self): def __init__(self):
@ -113,17 +127,3 @@ class PopenModule(AutoStartModule, metaclass=ABCMeta):
self.process.wait() self.process.wait()
self.process = None self.process = None
self.reader.stop() self.reader.stop()
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

View File

@ -74,17 +74,3 @@ class DirewolfModule(AutoStartModule):
self.process.wait() self.process.wait()
self.process = None self.process = None
self.reader.stop() self.reader.stop()
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