Make PipeIOServer non-blocking
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from threading import Event
|
||||
from threading import Thread, Event
|
||||
|
||||
from .pipe_reader_thread import PipeReaderThread
|
||||
from .pipe_writer_thread import PipeWriterThread
|
||||
from .pipe import Pipe
|
||||
from .terminate_process_on_failure import terminate_process_on_failure
|
||||
|
||||
|
||||
class PipeIOServer(ABC):
|
||||
class PipeIOServer(ABC, Thread):
|
||||
def __init__(self, in_pipe=None, out_pipe=None):
|
||||
super().__init__()
|
||||
self._in_pipe, self._out_pipe = in_pipe, out_pipe
|
||||
self._create_pipes()
|
||||
self._stop_event = Event()
|
||||
@ -38,6 +40,7 @@ class PipeIOServer(ABC):
|
||||
def send(self, message):
|
||||
self._writer_thread.write(message)
|
||||
|
||||
@terminate_process_on_failure
|
||||
def run(self):
|
||||
for thread in self._io_threads:
|
||||
thread.start()
|
||||
@ -46,6 +49,8 @@ class PipeIOServer(ABC):
|
||||
|
||||
def stop(self):
|
||||
self._stop_event.set()
|
||||
if self.is_alive():
|
||||
self.join()
|
||||
|
||||
def _stop(self):
|
||||
for thread in self._io_threads:
|
||||
|
Reference in New Issue
Block a user