Skip to content

Commit

Permalink
Ensure periodic saving fires immediately after runner task is finished (
Browse files Browse the repository at this point in the history
#440)

* Ensure periodic saving fires immediately after runner task is finished

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jbweston and pre-commit-ci[bot] authored Jul 19, 2023
1 parent 88f0258 commit b77e011
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion adaptive/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ def default_save(learner):
async def _saver():
while self.status() == "running":
method(self.learner)
await asyncio.sleep(interval)
# No asyncio.shield needed, as 'wait' does not cancel any tasks.
await asyncio.wait([self.task], timeout=interval)
method(self.learner) # one last time

self.saving_task = self.ioloop.create_task(_saver())
Expand Down
6 changes: 2 additions & 4 deletions docs/source/tutorial/tutorial.IntegratorLearner.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.5
jupytext_version: 1.14.7
kernelspec:
display_name: python3
name: python3
Expand Down Expand Up @@ -86,9 +86,7 @@ if not runner.task.done():

```{code-cell} ipython3
print(
"The integral value is {} with the corresponding error of {}".format(
learner.igral, learner.err
)
f"The integral value is {learner.igral} with the corresponding error of {learner.err}"
)
learner.plot()
```
Expand Down

0 comments on commit b77e011

Please sign in to comment.