Refactor example server to separate file
This commit is contained in:
parent
88ef32ede3
commit
4beed1056a
18
echo_server.py
Normal file
18
echo_server.py
Normal file
@ -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}')
|
@ -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}')
|
||||
|
Loading…
Reference in New Issue
Block a user