python-adaptive / adaptive

:chart_with_upwards_trend: Adaptive: parallel active learning of mathematical functions
http://adaptive.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.16k stars 60 forks source link

large delay when using start_periodic_saving #439

Closed jbweston closed 1 year ago

jbweston commented 1 year ago

The current implementation of 'start_periodic_saving' does await sleep(interval):

https://github.com/python-adaptive/adaptive/blob/88f02588cf66d0276b9b77da466aa71c7c1f1773/adaptive/runner.py#L839C1-L843C50

This means that there can be a large interval-length delay between the time the runner completes and the time that the last write is made by start_periodic_saving.

This is very confusing when you wait for the runner to finish with await runner.task and the results are not yet written.

Fix is to have the await await both the timeout and runner.task (remembering to shield runner.task)