Skip to content

Commit

Permalink
Fix deadly-embrace in refresh()
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltrails committed Feb 16, 2024
1 parent 30a2d13 commit b69b14a
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions vdu_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7350,7 +7350,7 @@ def lux_check_action(self) -> bool:

def start_refresh(self) -> None:
if not is_running_in_gui_thread():
log_debug("Reinvoke sart_refresh() in GUI thread.")
log_debug("Reinvoke start_refresh() in GUI thread.")
self.main_window.run_in_gui_thread(self.start_refresh)
return
assert is_running_in_gui_thread()
Expand All @@ -7361,38 +7361,40 @@ def start_refresh(self) -> None:

def update_from_vdu() -> None:
if self.ddcutil is not None:
with self.refresh_lock:
try:
self.ddcutil.refresh_connection()
self.detected_vdu_list = self.ddcutil.detect_monitors()
for control_panel in self.main_window.get_main_panel().vdu_control_panels.values():
if control_panel.controller.get_full_id() in self.detected_vdu_list:
control_panel.refresh_from_vdu()
except (subprocess.SubprocessError, ValueError, re.error, OSError) as e:
if self.refresh_data_task.vdu_exception is None:
self.refresh_data_task.vdu_exception = VduException(vdu_description="unknown", operation="unknown",
exception=e)
self.refresh_lock.acquire()
try:
self.ddcutil.refresh_connection()
self.detected_vdu_list = self.ddcutil.detect_monitors()
for control_panel in self.main_window.get_main_panel().vdu_control_panels.values():
if control_panel.controller.get_full_id() in self.detected_vdu_list:
control_panel.refresh_from_vdu()
except (subprocess.SubprocessError, ValueError, re.error, OSError) as e:
self.refresh_lock.release()
if self.refresh_data_task.vdu_exception is None:
self.refresh_data_task.vdu_exception = VduException(vdu_description="unknown", operation="unknown",
exception=e)


def update_ui_view(_: WorkerThread) -> None:
# Invoke when the worker thread completes. Runs in the GUI thread and can refresh remaining UI views.
try:
assert self.refresh_data_task is not None and is_running_in_gui_thread()
log_debug("Refresh - update UI view")
with self.refresh_lock: # An event may have cause a parallel refresh, let it finish
main_panel = self.main_window.get_main_panel()
if self.refresh_data_task.vdu_exception is not None:
main_panel.display_vdu_exception(self.refresh_data_task.vdu_exception, can_retry=False)
if len(self.detected_vdu_list) == 0 or self.detected_vdu_list != self.previously_detected_vdu_list:
log_info(f"Reconfiguring: detected vdu count={self.detected_vdu_list}")
self.configure_application() # May cause a further refresh?
self.previously_detected_vdu_list = self.detected_vdu_list
if self.lux_auto_controller:
if LuxDialog.exists():
lux_dialog: LuxDialog = LuxDialog.get_instance() # type: ignore
lux_dialog.reconfigure() # in case the number of connected monitors have changed.
self.lux_auto_controller.adjust_brightness_now()
main_panel = self.main_window.get_main_panel()
if self.refresh_data_task.vdu_exception is not None:
main_panel.display_vdu_exception(self.refresh_data_task.vdu_exception, can_retry=False)
if len(self.detected_vdu_list) == 0 or self.detected_vdu_list != self.previously_detected_vdu_list:
log_info(f"Reconfiguring: detected vdu count={self.detected_vdu_list}")
self.configure_application() # May cause a further refresh?
self.previously_detected_vdu_list = self.detected_vdu_list
if self.lux_auto_controller:
if LuxDialog.exists():
lux_dialog: LuxDialog = LuxDialog.get_instance() # type: ignore
lux_dialog.reconfigure() # in case the number of connected monitors have changed.
self.lux_auto_controller.adjust_brightness_now()
finally:
self.main_window.indicate_busy(False)
self.refresh_lock.release()

self.main_window.indicate_busy(True)
self.refresh_data_task = WorkerThread(task_body=update_from_vdu, task_finished=update_ui_view)
Expand Down

0 comments on commit b69b14a

Please sign in to comment.