Skip to content
Snippets Groups Projects
Commit 3450c4fb authored by Jorn Hoofwijk's avatar Jorn Hoofwijk Committed by Bas Nijholt
Browse files

exponentially decay message frequency in live_info

parent c816cf67
No related branches found
No related tags found
No related merge requests found
Pipeline #12499 passed
This commit is part of merge request !108. Comments created here will be created in the context of that merge request.
...@@ -4,6 +4,7 @@ import asyncio ...@@ -4,6 +4,7 @@ import asyncio
from contextlib import suppress from contextlib import suppress
import datetime import datetime
from pkg_resources import parse_version from pkg_resources import parse_version
import random
import warnings import warnings
...@@ -121,6 +122,25 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None): ...@@ -121,6 +122,25 @@ def live_plot(runner, *, plotter=None, update_interval=2, name=None):
return dm return dm
def should_update(status):
try:
# Get the length of the write buffer size
buffer_size = len(status.comm.kernel.iopub_thread._events)
# Make sure to only keep all the messages when the notebook
# is viewed, this means 'buffer_size == 1'. However, when not
# viewing the notebook the buffer fills up. When this happens
# we decide to only add messages to it when a certain probability.
# i.e. we're offline for 12h, with an update_interval of 0.5s,
# and without the reduced probability, we have buffer_size=86400.
# With the correction this is np.log(86400) / np.log(1.1) = 119.2
return 1.1**buffer_size * random.random() < 1
except Exception:
# We catch any Exception because we are using a private variable.
return True
def live_info(runner, *, update_interval=0.5): def live_info(runner, *, update_interval=0.5):
"""Display live information about the runner. """Display live information about the runner.
...@@ -143,7 +163,12 @@ def live_info(runner, *, update_interval=0.5): ...@@ -143,7 +163,12 @@ def live_info(runner, *, update_interval=0.5):
async def update(): async def update():
while not runner.task.done(): while not runner.task.done():
await asyncio.sleep(update_interval) await asyncio.sleep(update_interval)
status.value = _info_html(runner)
if should_update(status):
status.value = _info_html(runner)
else:
await asyncio.sleep(0.05)
status.value = _info_html(runner) status.value = _info_html(runner)
cancel.layout.display = 'none' cancel.layout.display = 'none'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment