Skip to content

Close ParticleFile after encountering kernel errors#2723

Open
VeckoTheGecko wants to merge 2 commits into
Parcels-code:mainfrom
VeckoTheGecko:push-lulsmzmlouvp
Open

Close ParticleFile after encountering kernel errors#2723
VeckoTheGecko wants to merge 2 commits into
Parcels-code:mainfrom
VeckoTheGecko:push-lulsmzmlouvp

Conversation

@VeckoTheGecko

Copy link
Copy Markdown
Contributor

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
    • Describe how you used it (e.g., by pasting your prompt): Guided the LLM output using the original issue and TDD.

Comment on lines -436 to +461
while sign_dt * (time - end_time) < 0:
if next_output is not None:
f = min if sign_dt > 0 else max
next_time = f(next_output, end_time)
else:
next_time = end_time

self._kernel.execute(self, endtime=next_time, dt=dt)

if next_output is not None:
if np.abs(next_time - next_output) < 0.001:
if output_file:
output_file.write(self, next_output)
if np.isfinite(outputdt):
next_output += outputdt * sign_dt

if verbose_progress:
pbar.set_description_str(
"Integration time: " + str(float_to_datelike(time, self.fieldset.time_interval))
)
pbar.update(sign_dt * (next_time - time))

time = next_time

if output_file is not None:
output_file.close()
with output_file if output_file is not None else nullcontext():
while sign_dt * (time - end_time) < 0:
if next_output is not None:
f = min if sign_dt > 0 else max
next_time = f(next_output, end_time)
else:
next_time = end_time

self._kernel.execute(self, endtime=next_time, dt=dt)

if next_output is not None:
if np.abs(next_time - next_output) < 0.001:
if output_file:
output_file.write(self, next_output)
if np.isfinite(outputdt):
next_output += outputdt * sign_dt

if verbose_progress:
pbar.set_description_str(
"Integration time: " + str(float_to_datelike(time, self.fieldset.time_interval))
)
pbar.update(sign_dt * (next_time - time))

time = next_time

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only difference with this block is the indentation and the with statement

@VeckoTheGecko VeckoTheGecko changed the title Close ParticleFile after errors Close ParticleFile after encountering kernel errors Jul 6, 2026

@erikvansebille erikvansebille left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@VeckoTheGecko VeckoTheGecko enabled auto-merge (squash) July 6, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Parcels parquet output files can't (always) be opened after a run crashes

2 participants