Skip to content

Commit

Permalink
Fix deadlock update() inside Control.did_mount()
Browse files Browse the repository at this point in the history
Fix #489
  • Loading branch information
FeodorFitsner committed Oct 27, 2022
1 parent 15a375c commit a27bcfc
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions sdk/python/flet/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,16 @@ def _fetch_page_details(self):
self._set_attr("windowLeft", values[9], False)

def update(self, *controls):
added_controls = []
with self._lock:
if len(controls) == 0:
return self.__update(self)
added_controls = self.__update(self)
else:
return self.__update(*controls)
added_controls = self.__update(*controls)
for ctrl in added_controls:
ctrl.did_mount()

def __update(self, *controls):
def __update(self, *controls) -> List[Control]:
added_controls = []
commands = []

Expand All @@ -204,7 +207,7 @@ def __update(self, *controls):
control.build_update_commands(self._index, added_controls, commands)

if len(commands) == 0:
return
return added_controls

# execute commands
results = self.__conn.send_commands(self._session_id, commands).results
Expand All @@ -219,34 +222,44 @@ def __update(self, *controls):
# add to index
self._index[id] = added_controls[n]

# call Control.did_mount
added_controls[n].did_mount()

n += 1
return added_controls

def add(self, *controls):
added_controls = []
with self._lock:
self._controls.extend(controls)
return self.__update(self)
added_controls = self.__update(self)
for ctrl in added_controls:
ctrl.did_mount()

def insert(self, at, *controls):
added_controls = []
with self._lock:
n = at
for control in controls:
self._controls.insert(n, control)
n += 1
return self.__update(self)
added_controls = self.__update(self)
for ctrl in added_controls:
ctrl.did_mount()

def remove(self, *controls):
added_controls = []
with self._lock:
for control in controls:
self._controls.remove(control)
return self.__update(self)
added_controls = self.__update(self)
for ctrl in added_controls:
ctrl.did_mount()

def remove_at(self, index):
added_controls = []
with self._lock:
self._controls.pop(index)
return self.__update(self)
added_controls = self.__update(self)
for ctrl in added_controls:
ctrl.did_mount()

def clean(self):
with self._lock:
Expand Down

0 comments on commit a27bcfc

Please sign in to comment.