Ensure Pipe*Server classes are ready for use after start() returns

This commit is contained in:
Kristóf Tóth 2019-09-05 13:56:50 +02:00
parent b98a1df962
commit 8b6e82be38
3 changed files with 13 additions and 3 deletions

View File

@ -9,11 +9,14 @@ class PipeIOThread(Thread):
self._stop_event = Event() self._stop_event = Event()
self.__io_threads = [] self.__io_threads = []
@terminate_process_on_failure def start(self):
def run(self): super().start()
self.__io_threads.extend(self._io_threads()) self.__io_threads.extend(self._io_threads())
for thread in self.__io_threads: for thread in self.__io_threads:
thread.start() thread.start()
@terminate_process_on_failure
def run(self):
self._stop_event.wait() self._stop_event.wait()
self._stop_threads() self._stop_threads()

View File

@ -224,3 +224,10 @@ def test_assign_message_handler():
test_data = token_urlsafe(32).encode() test_data = token_urlsafe(32).encode()
io_pipes.send_message(test_data) io_pipes.send_message(test_data)
assert io_pipes.recv() == test_data * 2 assert io_pipes.recv() == test_data * 2
def test_write_immediately():
for _ in range(10):
pipe_io = PipeIOServer(*get_test_init_params())
with pipe_io:
pipe_io.send_message(b'cica')

View File

@ -5,7 +5,7 @@ with open('README.md', 'r') as ifile:
setup( setup(
name='pipe_io_server', name='pipe_io_server',
version='1.0.1', version='1.0.2',
author='Kristóf Tóth', author='Kristóf Tóth',
author_email='mrtoth@strongds.hu', author_email='mrtoth@strongds.hu',
description='A trivial to use IPC solution based on pipes and newlines', description='A trivial to use IPC solution based on pipes and newlines',