Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The on_change event of ui.input is stuck in a loop #1086

Closed
CrystalWindSnake opened this issue Jun 26, 2023 · 1 comment
Closed

The on_change event of ui.input is stuck in a loop #1086

CrystalWindSnake opened this issue Jun 26, 2023 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@CrystalWindSnake
Copy link
Contributor

CrystalWindSnake commented Jun 26, 2023

Description

This issue seems to be quite serious.

from nicegui import ui
from time import sleep

count = 0

def onchange():
    global count
    count += 1
    print("onchage:", count)
    sleep(1)
    input1.update()

input1 = ui.input(on_change=onchange)

ui.run()

continuously enter the letter 'd' in the input box. The console can see that the on_change event is triggered repeatedly.

@falkoschindler
Copy link
Contributor

Thanks for reporting this bug, @CrystalWindSnake!

First I have to say: Event handlers should not block code execution for so long. Sleeping synchronously for 1 second will freeze the UI. Expensive computations should run in an executor.

But there are certainly scenarios where change events come in very frequently and processing might take a bit too long. Then, of course, the displayed value should not oscillate. So this issue is totally valid.

I think I could fix it in 1c30ef1 by disabling change events while processing an update from the server.

@falkoschindler falkoschindler added this to the 1.2.23 milestone Jun 26, 2023
@falkoschindler falkoschindler self-assigned this Jun 26, 2023
@falkoschindler falkoschindler added the bug Something isn't working label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants