Make pipe path attributes of PipeIOServer properties

This commit is contained in:
Kristóf Tóth 2018-12-16 23:28:33 +01:00
parent 512247163c
commit 2aa673d2c9

View File

@ -10,7 +10,7 @@ from .pipe import Pipe
class PipeIOServer(ABC):
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._init_io_threads()
@ -18,11 +18,19 @@ class PipeIOServer(ABC):
def _create_pipes(self):
if not self.in_pipe or not self.out_pipe:
pipe_id = token_urlsafe(6)
self.in_pipe = join('/tmp', f'in_pipe_{pipe_id}')
self.out_pipe = join('/tmp', f'out_pipe_{pipe_id}')
self._in_pipe = join('/tmp', f'in_pipe_{pipe_id}')
self._out_pipe = join('/tmp', f'out_pipe_{pipe_id}')
Pipe(self.in_pipe).recreate()
Pipe(self.out_pipe).recreate()
@property
def in_pipe(self):
return self._in_pipe
@property
def out_pipe(self):
return self._out_pipe
def _init_io_threads(self):
io_threads_dict = {
'reader': PipeReaderThread(self.in_pipe, self.handle_message),