Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions OpenLIFULib/OpenLIFULib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ def __init__(self, name_to_print, use_dialogs=True, *args, **kwargs):
self.use_dialogs = use_dialogs

def emit(self, record):
# Qt UI calls are only safe on the main thread. If this log record was emitted
# from a background thread (e.g. UART monitor/read threads), skip Qt interactions
# entirely to avoid QObject::setParent and processEvents cross-thread crashes.
if qt.QThread.currentThread() is not slicer.app.thread():
return
Comment on lines 75 to +80

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This early return drops all Slicer UI surfacing for log records emitted off the main thread (including warnings/errors). If this handler is the primary feedback path for these loggers, important messages may be silently lost. Consider queuing the UI work onto the main thread (e.g., via a singleShot/invokeMethod) or at least falling back to non-Qt output when off-thread, instead of returning.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe at least log something so that we know it is dropping


if record.levelno == logging.ERROR:
method_to_use = self.handle_error_with_dialog if self.use_dialogs else self.handle_error_without_dialog
elif record.levelno == logging.WARNING:
Expand Down
Loading
Loading