The type annotations of PeriodicCallback state callback: Callable[[], None]. The documentation does not clarify.
Both the annotations and the docstring should clarify that both sync and async functions, as well as sync functions that return Futures, are valid callbacks (callback: Callable[[], None] | Callable[[], Awaitable[None]).
However, this note in the docstring:
If the callback runs for longer than ``callback_time`` milliseconds,
subsequent invocations will be skipped to get back on schedule.
only seems to apply to sync functions; this should either be fixed or clarified in the docs.
The code below prints "foo" every 1 second instead of 3:
async def foo():
await asyncio.sleep(3)
print("foo")
pc = PeriodicCallback(foo, 1000)
The type annotations of PeriodicCallback state
callback: Callable[[], None]. The documentation does not clarify.Both the annotations and the docstring should clarify that both sync and async functions, as well as sync functions that return Futures, are valid callbacks (
callback: Callable[[], None] | Callable[[], Awaitable[None]).However, this note in the docstring:
only seems to apply to sync functions; this should either be fixed or clarified in the docs.
The code below prints "foo" every 1 second instead of 3: