diff --git a/pipe_io_server/pipe_io_server.py b/pipe_io_server/pipe_io_server.py index 8a7398c..5568f49 100644 --- a/pipe_io_server/pipe_io_server.py +++ b/pipe_io_server/pipe_io_server.py @@ -26,14 +26,9 @@ class PipeHandler: class PipeIOServer(ABC): def __init__(self, in_pipe=None, out_pipe=None): self.in_pipe, self.out_pipe = in_pipe, out_pipe + self._io_threads = None self._create_pipes() - - 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) + self._init_io_threads() def _create_pipes(self): 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}') 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 def _handle_message(self, message): raise NotImplementedError()