Skip to content

Commit 629cd87

Browse files
committed
MNT: narrow what the failure path swallows, and log the change
Review practice on this repository is consistent about breadth: broad exception handlers get asked about, and a guard that cannot fire gets asked to go. Both applied here. terminate and kill were wrapped against a process that dies between the liveness check and the signal. multiprocess already swallows ProcessLookupError there and retries once on OSError, so the wrapper could not fire and is gone. The three that remain say what they expect. A manager that has gone away answers a proxy call with a broken connection or an EOF, a log that cannot be written raises OSError, and a closed stream raises OSError or ValueError. Anything else now reaches the caller. One CHANGELOG line, since one pull request is one line here and the workflow that would have written it has not run since #1112 (#1173). Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
1 parent 141503a commit 629cd87

2 files changed

Lines changed: 19 additions & 24 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Attention: The newest changes should be on top -->
6060

6161
### Fixed
6262

63+
- BUG: Report a Monte Carlo worker that fails instead of hanging or passing for a finished run [#1182](https://github.com/RocketPy-Team/RocketPy/pull/1182)
6364
- BUG: Sample `StochasticFlight` inputs once per simulation [#1126](https://github.com/RocketPy-Team/RocketPy/pull/1126) [#1090](https://github.com/RocketPy-Team/RocketPy/issues/1090)
6465
- BUG: Fix spurious `ValueError` from floating-point roundoff at exact tank depletion [#1166](https://github.com/RocketPy-Team/RocketPy/pull/1166)
6566
- BUG: Draw each declared eccentricity once per simulation [#1168](https://github.com/RocketPy-Team/RocketPy/pull/1168)

‎rocketpy/simulation/monte_carlo.py‎

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
# Which simulation a row belongs to. Every check on a finished run reads it.
4848
_SIMULATION_INDEX_KEY = "index"
4949

50+
# How a manager that has gone away answers a proxy call.
51+
_MANAGER_IS_GONE = (OSError, EOFError)
52+
5053

5154
def _refuse_logs_this_run_cannot_write(
5255
input_file, output_file, error_file, export_config=None
@@ -612,16 +615,16 @@ def __report_a_failed_simulation(self, sim_idx, inputs_json, mutex, error_event)
612615
details = traceback.format_exc()
613616
where = "worker startup" if sim_idx is None else f"iteration {sim_idx}"
614617
announced = False
615-
with suppress(Exception):
618+
with suppress(_MANAGER_IS_GONE):
616619
error_event.set()
617620
announced = True
618621

619622
mutex.acquire()
620623
try:
621-
with suppress(Exception):
624+
with suppress(OSError):
622625
with open(self.error_file, "a", encoding="utf-8") as f:
623626
f.write(inputs_json or _worker_failure_record(where, details))
624-
with suppress(Exception):
627+
with suppress(OSError, ValueError):
625628
# Must use print() to remain visible from a worker process.
626629
_SimMonitor.reprint(f"Error on {where}:\n{details}")
627630
finally:
@@ -1821,10 +1824,9 @@ def _ended_badly(worker):
18211824

18221825

18231826
def _wait_for_the_workers(processes, seconds):
1824-
"""Join every worker against one shared deadline, not one deadline each.
1827+
"""Join every worker against one shared deadline, not one each.
18251828
1826-
``monotonic`` rather than the wall clock, which a correction can move
1827-
underneath a shutdown already in progress.
1829+
Monotonic, since a clock correction would move a wall-clock deadline.
18281830
"""
18291831
deadline = monotonic() + seconds
18301832
for worker in processes:
@@ -1839,33 +1841,28 @@ def _stop_the_workers_still_running(processes, error_event, grace_period):
18391841
never reaches that check. Terminate runs no handlers, so it comes second,
18401842
and a worker can still ignore it.
18411843
"""
1842-
with suppress(Exception):
1844+
with suppress(_MANAGER_IS_GONE):
18431845
error_event.set()
18441846
_wait_for_the_workers(processes, grace_period)
18451847

18461848
for worker in processes:
18471849
if worker.is_alive():
1848-
with suppress(Exception):
1849-
worker.terminate()
1850+
worker.terminate()
18501851
_wait_for_the_workers(processes, grace_period)
18511852

18521853
for worker in processes:
18531854
if worker.is_alive():
1854-
with suppress(Exception):
1855-
worker.kill()
1855+
worker.kill()
18561856
_wait_for_the_workers(processes, grace_period)
18571857

18581858

18591859
def _join_the_workers(processes, error_event, grace_period=_SHUTDOWN_GRACE_SECONDS):
1860-
"""Wait for the workers, and stop waiting once one of them has died badly.
1861-
1862-
The lock the workers share belongs to the manager and is not released when
1863-
its holder is killed, so a sibling can block on a lock nobody owns while an
1864-
unbounded join waits with it. Nothing here bounds a run that is merely
1865-
slow, and a reported failure does not either: a worker that reports has
1866-
left nothing behind, and its siblings stop of their own accord once they
1867-
finish the simulation in hand. Only a worker that died can hold the lock
1868-
for good.
1860+
"""Wait for the workers, and stop once one of them has died badly.
1861+
1862+
The shared lock belongs to the manager and outlives a killed holder, so a
1863+
sibling can block on a lock nobody owns. Neither slowness nor a reported
1864+
failure ends the wait: a worker that reports leaves nothing behind, and
1865+
its siblings stop once they finish the simulation in hand.
18691866
"""
18701867
while any(worker.is_alive() for worker in processes):
18711868
for worker in processes:
@@ -1876,10 +1873,7 @@ def _join_the_workers(processes, error_event, grace_period=_SHUTDOWN_GRACE_SECON
18761873

18771874

18781875
def _worker_failure_record(where, details):
1879-
"""A row for a worker that failed before it drew anything.
1880-
1881-
The caller is sent to this file, and a printed traceback is not in it.
1882-
"""
1876+
"""A row for a worker that failed before it drew anything."""
18831877
return json.dumps({"index": None, "stage": where, "error": details}) + "\n"
18841878

18851879

0 commit comments

Comments
 (0)