Refactor PipeIOServer.__init__()
This commit is contained in:
parent
5091380133
commit
09abb0331d
@ -26,14 +26,9 @@ class PipeHandler:
|
|||||||
class PipeIOServer(ABC):
|
class PipeIOServer(ABC):
|
||||||
def __init__(self, in_pipe=None, out_pipe=None):
|
def __init__(self, in_pipe=None, out_pipe=None):
|
||||||
self.in_pipe, self.out_pipe = in_pipe, out_pipe
|
self.in_pipe, self.out_pipe = in_pipe, out_pipe
|
||||||
|
self._io_threads = None
|
||||||
self._create_pipes()
|
self._create_pipes()
|
||||||
|
self._init_io_threads()
|
||||||
io_threads_dict = {
|
|
||||||
'reader': PipeReaderThread(self.in_pipe, self._handle_message),
|
|
||||||
'writer': PipeWriterThread(self.out_pipe)
|
|
||||||
}
|
|
||||||
IOThreadsTuple = namedtuple('IOThreadsTuple', sorted(io_threads_dict.keys()))
|
|
||||||
self._io_threads = IOThreadsTuple(**io_threads_dict)
|
|
||||||
|
|
||||||
def _create_pipes(self):
|
def _create_pipes(self):
|
||||||
if not self.in_pipe or not self.out_pipe:
|
if not self.in_pipe or not self.out_pipe:
|
||||||
@ -42,6 +37,14 @@ class PipeIOServer(ABC):
|
|||||||
self.out_pipe = join('/tmp', f'out_pipe_{pipe_id}')
|
self.out_pipe = join('/tmp', f'out_pipe_{pipe_id}')
|
||||||
PipeHandler(self.in_pipe, self.out_pipe).recreate()
|
PipeHandler(self.in_pipe, self.out_pipe).recreate()
|
||||||
|
|
||||||
|
def _init_io_threads(self):
|
||||||
|
io_threads_dict = {
|
||||||
|
'reader': PipeReaderThread(self.in_pipe, self._handle_message),
|
||||||
|
'writer': PipeWriterThread(self.out_pipe)
|
||||||
|
}
|
||||||
|
IOThreadsTuple = namedtuple('IOThreadsTuple', sorted(io_threads_dict.keys()))
|
||||||
|
self._io_threads = IOThreadsTuple(**io_threads_dict)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _handle_message(self, message):
|
def _handle_message(self, message):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
Loading…
Reference in New Issue
Block a user