Skip to content

Commit bab5d13

Browse files
committed
Fix thread-related plotting crash on Linux.
Plotter.notify was called from the fitting thread. This caused hard crash when plot windows were updated during refinement. Solution: Use thread-safe postEvent function to request plot updates.
1 parent 99aa65a commit bab5d13

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

diffpy/pdfgui/control/calculation.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,7 @@ def start(self):
130130
gui = self.owner.controlCenter.gui
131131
if gui:
132132
gui.postEvent(gui.OUTPUT, None)
133-
try:
134-
gui.lock()
135-
for plot in self.owner.controlCenter.plots:
136-
plot.notify(self)
137-
finally:
138-
gui.unlock()
133+
gui.postEvent(gui.PLOTNOW, self)
139134
return
140135

141136
def calculate(self):

diffpy/pdfgui/control/fitting.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -723,14 +723,7 @@ def refine_step(self):
723723
gui = self.controlCenter.gui
724724
if gui:
725725
gui.postEvent(gui.OUTPUT, None)
726-
try:
727-
if gui:
728-
gui.lock()
729-
for plot in self.controlCenter.plots:
730-
plot.notify(self)
731-
finally:
732-
if gui:
733-
gui.unlock()
726+
gui.postEvent(gui.PLOTNOW, self)
734727

735728
if finished:
736729
self.res = "* %s\n\n"%time.ctime()+ self.server.save_res_string()

diffpy/pdfgui/gui/mainframe.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def __customProperties(self):
286286
self.ERROR = 1
287287
self.UPDATE = 1<<1
288288
self.OUTPUT = 1<<2
289+
self.PLOTNOW = 1<<3
289290

290291
# Needed for the error checker so it doesn't throw errors at quit time
291292
self.quitting = False
@@ -2472,6 +2473,11 @@ def onCustom(self, event):
24722473
self.updateFittingStatus(job)
24732474
elif event.type == self.OUTPUT:
24742475
self.updateOutput()
2476+
elif event.type == self.PLOTNOW:
2477+
# job is a fitting or a calculation with a new data to plot.
2478+
job = event.info
2479+
for plot in self.control.plots:
2480+
plot.notify(job)
24752481
return
24762482

24772483
def updateFittingStatus(self, job):

0 commit comments

Comments
 (0)