From 290712d64fca64bfe5b0a6c2b580f0a45caf7e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 13 Dec 2018 22:16:02 +0100 Subject: [PATCH] Make PipeHandler able handle more pipes --- pipe_io_server.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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__":