smhk

NiceGUI: Change threshold for binding propagation warning

In NiceGUI you may start to see a binding propagation warning logged repeatedly if you have lots of binding.

For example:

WARNING:root:binding propagation for 626 active links took 0.010 s
WARNING:root:binding propagation for 626 active links took 0.015 s
WARNING:root:binding propagation for 626 active links took 0.012 s
WARNING:root:binding propagation for 626 active links took 0.013 s
WARNING:root:binding propagation for 626 active links took 0.012 s

Origin of the warning §

This logging comes from NiceGUI, from these lines in binding.py:

binding.py
    if time.time() - t > MAX_PROPAGATION_TIME:
        globals.log.warning(
            f'binding propagation for {len(active_links)} active links took {time.time() - t:.3f} s')

Changing the warning threshold §

Unfortunately there is no “nice” way to change the value of MAX_PROPAGATION_TIME, since it is defined at the top of binding.py as follows:

binding.py
MAX_PROPAGATION_TIME = 0.01

However, since this is Python where nothing is truly private, you can just monkeypatch NiceGUI:

import nicegui.binding

# Increase threshold for binding propagation warning from 0.01 to 0.02 seconds
nicegui.binding.MAX_PROPAGATION_TIME = 0.02