Skip to content

Commit

Permalink
fix child_processes being empty and exit from main loop when is_alive…
Browse files Browse the repository at this point in the history
… of another process returns False
  • Loading branch information
maximilianpilz committed Jan 23, 2023
1 parent cd068df commit 1edacf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mpunittest/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def addUnexpectedSuccess(
self.test_id_to_result_mapping[test.id()] = MergeableResult.Result.FAIL

def wasSuccessful(self) -> bool:
# TODO: implement while considering expected failures
# TODO: consider expected failures
return self.overall_result() == self.Result.PASS

def stop(self) -> None:
Expand Down
17 changes: 17 additions & 0 deletions src/mpunittest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self,
:param daemons: will be used as daemon flag for process creation
:param result_class: type to instantiate for saving unittest results
"""
assert process_count > 0
self._process_count = process_count

if mp_context is None:
Expand Down Expand Up @@ -203,6 +204,11 @@ def discover_and_run(

process_conn_with_process_tuples.append((respective_parent_conn, child_conn, child_process))
parent_conn_to_process_mapping[respective_parent_conn] = child_process
child_processes.append(child_process)

assert set(child_processes) == \
set(parent_conn_to_process_mapping.values()) == \
set((p for _, __, p in process_conn_with_process_tuples))

self._logger.debug('primary runner process will start discovery in directory "%s" '
'with pattern "%s" and top level directory "%s"',
Expand All @@ -224,6 +230,7 @@ def discover_and_run(
for conn, _, process in process_conn_with_process_tuples:
try:
test_id = test_ids.pop()
# TODO: check whether it is writeable
conn.send(test_id) # TODO: consider doing this in while True loop below
self._logger.info('primary runner process delegated run of %s to %s',
test_id, process.name)
Expand All @@ -242,7 +249,16 @@ def discover_and_run(

test_results = list()

assert child_processes
loop_counter = 0
while True:
if loop_counter == 0:
if not all(map(multiprocessing.Process.is_alive, child_processes)):
raise RuntimeError('At least one process terminated prematurely.')

loop_counter += 1
loop_counter %= 100

if platform.system() != 'Windows':
read_events = read_selector.select(timeout=0.001)
for key, mask in read_events:
Expand Down Expand Up @@ -317,6 +333,7 @@ def discover_and_run(
respective_parent_conn.close()

self._logger.debug('will wait for child processes to finish')
assert child_processes
for child_process in child_processes:
child_process.join()
exit_code = child_process.exitcode
Expand Down

0 comments on commit 1edacf3

Please sign in to comment.