Skip to content

Commit

Permalink
More accurate timing for pyodide periodic callbacks (#3390)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Apr 15, 2022
1 parent 7b36c94 commit 3d43e1c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions panel/io/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ async def _async_repeat(self, func):
immediately when the previous iteration finished.
"""
while True:
self._cb = asyncio.gather(
func(), asyncio.sleep(self.period/1000.),
)
start = time.monotonic()
self._cb = asyncio.ensure_future(func())
await self._cb

timeout = (self.period/1000.) - (time.monotonic()-start)
if timeout > 0:
self._cb = asyncio.ensure_future(asyncio.sleep(timeout))
await self._cb

def _cleanup(self, session_context):
self.stop()

Expand Down

0 comments on commit 3d43e1c

Please sign in to comment.