pipe-io-server/pipe_io_server/pipe_writer_server.py

30 lines
835 B
Python

from .pipe import Pipe, DEFAULT_PERMISSIONS
from .pipe_io_thread import PipeIOThread
from .pipe_writer_thread import PipeWriterThread
class PipeWriterServer(PipeIOThread):
def __init__(self, out_pipe, permissions=DEFAULT_PERMISSIONS, **kwargs):
super().__init__(**kwargs)
self._out_pipe = out_pipe
Pipe(self.out_pipe).recreate(permissions)
self._writer_thread = None
@property
def out_pipe(self):
return self._out_pipe
def _init_io_thread(self):
self._writer_thread = PipeWriterThread(
self.out_pipe,
self._stop_event
)
self._io_threads.append(self._writer_thread)
def send_message(self, message):
self._writer_thread.write(message)
def stop(self):
super().stop()
Pipe(self.out_pipe).remove()