flet icon indicating copy to clipboard operation
flet copied to clipboard

Calling `update()` inside `Control.did_mount()` causes deadlock

Open FeodorFitsner opened this issue 3 years ago • 0 comments

Sample code causing deadlock:

import flet
from flet import Container, Page, Text, UserControl

class MyControl(UserControl):
    def build(self):
        print("i am built")
        self.c = Container()
        self.c.bgcolor = "blue"
        self.c.content = Text("hello there")
        return self.c

    def did_mount(self):
        print("i am mounted")
        self.resize_me()

    def resize_me(self):
        self.c.bgcolor = "red"
        self.update()

def main(page: Page):
    t = MyControl()
    page.add(t)
    print("i am added")

flet.app(target=main)

Solution:

Go through a list of added controls after update() is finished and lock released and call did_mount() for each added control.

FeodorFitsner avatar Oct 17 '22 16:10 FeodorFitsner