diff --git a/pipe_io_server.py b/pipe_io_server.py index 934811f..71241c6 100644 --- a/pipe_io_server.py +++ b/pipe_io_server.py @@ -48,16 +48,18 @@ class PipeReaderThread(Thread): class PipeHandler: - def __init__(self, pipe_path): - self._pipe_path = pipe_path + def __init__(self, *pipe_paths): + self._pipe_paths = pipe_paths def recreate(self): self.remove() - mkfifo(self._pipe_path) + for pipe_path in self._pipe_paths: + mkfifo(pipe_path) def remove(self): - if exists(self._pipe_path): - remove(self._pipe_path) + for pipe_path in self._pipe_paths: + if exists(pipe_path): + remove(pipe_path) class PipeIOServer: @@ -76,8 +78,7 @@ class PipeIOServer: 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}') - PipeHandler(self.in_pipe).recreate() - PipeHandler(self.out_pipe).recreate() + PipeHandler(self.in_pipe, self.out_pipe).recreate() def run(self): for thread in self._io_threads.values(): @@ -86,8 +87,7 @@ class PipeIOServer: def stop(self): for thread in self._io_threads.values(): thread.stop() - PipeHandler(self.in_pipe).remove() - PipeHandler(self.out_pipe).remove() + PipeHandler(self.in_pipe, self.out_pipe).remove() if __name__ == "__main__":