pipe-io-server/pipe_io_server/pipe_writer_server.py
2019-07-30 13:04:08 +02:00

30 lines
812 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 _io_threads(self):
self._writer_thread = PipeWriterThread(
self.out_pipe,
self._stop_event
)
yield self._writer_thread
def send_message(self, message):
self._writer_thread.write(message)
def stop(self):
super().stop()
Pipe(self.out_pipe).remove()