Skip to content

Commit

Permalink
Merge pull request #626 from ISISNeutronMuon/chi/runtimeerror-on-gui-…
Browse files Browse the repository at this point in the history
…close-fix

Fixes runtime error seen after the GUI is closed when jobs have been terminated.
  • Loading branch information
MBartkowiakSTFC authored Jan 3, 2025
2 parents a2de464 + 8dc8512 commit 405b94b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
42 changes: 24 additions & 18 deletions MDANSE_GUI/Src/MDANSE_GUI/Tabs/Models/JobHolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,25 @@ def run(self):
self._job_comm.status_update(status_update)


class JobEntry(Handler, QObject):
class JobLogHandler(Handler):

def __init__(self):
super().__init__()
self.records = []

def msgs_and_levels(self):
msgs = []
levels = []
for record in self.records:
msgs.append(self.format(record))
levels.append(record.levelname)
return msgs, levels

def emit(self, record):
self.records.append(record)


class JobEntry(QObject):
"""This coordinates all the objects that make up one line on the list
of current jobs. It is used for reporting the task progress to the GUI."""

Expand All @@ -104,8 +122,7 @@ def __init__(
pause_event=None,
load_afterwards=False,
):
super().__init__()
QObject.__init__(self)
super().__init__(*args)
self._command = command
self._finished = False
self._parameters = {}
Expand All @@ -132,7 +149,7 @@ def __init__(
self._prog_item.setData("progress", role=Qt.ItemDataRole.DisplayRole)
self._prog_item.setData(0, role=ProgressDelegate.progress_role)
self._prog_item.setData(100, role=ProgressDelegate.progress_role + 1)
self.records = []
self.handler = JobLogHandler()

def text_summary(self) -> str:
result = ""
Expand Down Expand Up @@ -232,17 +249,6 @@ def kill_job(self):
self._current_state.kill()
self.update_fields()

def msgs_and_levels(self):
msgs = []
levels = []
for record in self.records:
msgs.append(self.format(record))
levels.append(record.levelname)
return msgs, levels

def emit(self, record):
self.records.append(record)


class JobHolder(QStandardItemModel):
"""All the job INSTANCES that are started by the GUI
Expand Down Expand Up @@ -288,8 +294,8 @@ def startProcess(self, job_vars: list, load_afterwards=False):
pause_event=pause_event,
load_afterwards=load_afterwards,
)
item_th.setFormatter(FMT)
item_th.setLevel("INFO")
item_th.handler.setFormatter(FMT)
item_th.handler.setLevel("INFO")

try:
subprocess_ref = Subprocess(
Expand All @@ -307,7 +313,7 @@ def startProcess(self, job_vars: list, load_afterwards=False):
)
return

handlers = [item_th] + LOG.handlers
handlers = [item_th.handler] + LOG.handlers
listener = QueueListener(log_queue, *handlers, respect_handler_level=True)
listener.start()

Expand Down
2 changes: 1 addition & 1 deletion MDANSE_GUI/Src/MDANSE_GUI/Tabs/Views/RunTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def item_picked(self, index: QModelIndex):
node_number = model.index(item_row, 0).data(role=Qt.ItemDataRole.UserRole)
job_entry = model.existing_jobs[node_number]
self.item_details.emit(job_entry.text_summary())
self.jobs_logs.emit(job_entry.msgs_and_levels())
self.jobs_logs.emit(job_entry.handler.msgs_and_levels())

def connect_to_visualiser(self, visualiser: TextInfo) -> None:
"""Connect to a visualiser.
Expand Down

0 comments on commit 405b94b

Please sign in to comment.