diff --git a/echo_server.py b/echo_server.py new file mode 100644 index 0000000..faef8c6 --- /dev/null +++ b/echo_server.py @@ -0,0 +1,18 @@ +from signal import signal, SIGTERM, SIGINT + +from pipe_io_server import PipeIOServer + + +class EchoPipeIOServer(PipeIOServer): + def _handle_message(self, message): + self.send(message) + + +if __name__ == "__main__": + pipe_io = EchoPipeIOServer() + signal(SIGTERM, lambda a, b: pipe_io.stop()) + signal(SIGINT, lambda a, b: pipe_io.stop()) + pipe_io.run() + print('Running pipe IO server with named pipes:') + print(f'Input: {pipe_io.in_pipe}') + print(f'Output: {pipe_io.out_pipe}') diff --git a/pipe_io_server.py b/pipe_io_server.py index accf535..8659583 100644 --- a/pipe_io_server.py +++ b/pipe_io_server.py @@ -2,7 +2,6 @@ from threading import Thread from queue import Queue from os import mkfifo, remove from os.path import exists, join -from signal import signal, SIGTERM, SIGINT from secrets import token_urlsafe from collections import namedtuple from abc import ABC, abstractmethod @@ -101,18 +100,3 @@ class PipeIOServer(ABC): for thread in self._io_threads: thread.stop() PipeHandler(self.in_pipe, self.out_pipe).remove() - - -class EchoPipeIOServer(PipeIOServer): - def _handle_message(self, message): - self.send(message) - - -if __name__ == "__main__": - pipe_io = EchoPipeIOServer() - signal(SIGTERM, lambda a, b: pipe_io.stop()) - signal(SIGINT, lambda a, b: pipe_io.stop()) - pipe_io.run() - print('Running pipe IO server with named pipes:') - print(f'Input: {pipe_io.in_pipe}') - print(f'Output: {pipe_io.out_pipe}')