Skip to content

Commit

Permalink
Fix Pr failure ticket #273
Browse files Browse the repository at this point in the history
 
 Long version:  In August 2013 it was determined that many instability problems experienced by SasView were do to a threading problem in fitting.py.  Mainly the authors seemed to not realize that calling thread.stop just raised a flag and that the thread itself needed to check for said flag regularly and kill the thread if it found the flag raised.  A quick fix was implemented by adding a wait till the existing thread ended naturally to the two places in the code where the stop is raised.  This seems to work.  

At the same time pr.py was found to use the same raising of the stop flag three times and it was assumed that the same problem existed and the same wait “fix” was implemented.  Subsequenty it has been shown that the new wait code in pr.py NEVER gets reached and thus the fix breaks the PrView perspective.  It may be that this earlier code properly dealt with threads properly(still remembering how the thread code was meant to be used).  Whatever the case will remove this fix for now.   

Finally another thread.stop was found once in simulation.py.  since this is older code it may also be handled properly so am removing the “Fix” from that as well for now.

to quickly find these points in the future: 
fitting.py - two instances that seem to need fixing
pr.py - three instances that may work correctly
simulation.py - one instace

search terms:
“-PDB” or
“d.stop” (thread.stop or thread_1D.stop or 2D.stop)
  • Loading branch information
butlerpd committed Jan 25, 2015
1 parent 5ba88d3 commit f3efa09
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
51 changes: 30 additions & 21 deletions src/sans/perspectives/pr/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,17 @@ def start_thread(self):
if self.calc_thread != None and self.calc_thread.isrunning():
self.calc_thread.stop()
## stop just raises the flag -- the thread is supposed to
## then kill itself but cannot. Paul Kienzle came up with
## this fix to prevent threads from stepping on each other
## in Calc1D of fitting.py which was causing a simple custom model
## to crash Sasview. See rest of notes under Calc1D.
## then kill itself. In August 2014 it was shown that this is
## incorrectly handled by fitting.py and a fix implemented.
## It is not clear whether it is properly used here, but the
## "fix" of waiting for the previous thread to end breaks the
## pr perspective completely as it causes an infinite loop.
## Thus it is likely the threading is bing properly handled.
## While the "fix" is no longer implemented the comment is
## left here till somebody ascertains that in fact the threads
## are being properly handled.
##
## -PDB August 13, 2014
while self.calc_thread.isrunning():
time.sleep(0.1)
## -PDB January 25, 2015

pr = self.pr.clone()
self.calc_thread = CalcPr(pr, self.nfunc,
Expand Down Expand Up @@ -1152,14 +1155,17 @@ def perform_estimate(self):
self.estimation_thread.isrunning():
self.estimation_thread.stop()
## stop just raises the flag -- the thread is supposed to
## then kill itself but cannot. Paul Kienzle came up with
## this fix to prevent threads from stepping on each other
## in Calc1D of fitting.py which was causing a simple custom model
## to crash Sasview. See rest of notes under Calc1D.
## then kill itself. In August 2014 it was shown that this is
## incorrectly handled by fitting.py and a fix implemented.
## It is not clear whether it is properly used here, but the
## "fix" of waiting for the previous thread to end breaks the
## pr perspective completely as it causes an infinite loop.
## Thus it is likely the threading is bing properly handled.
## While the "fix" is no longer implemented the comment is
## left here till somebody ascertains that in fact the threads
## are being properly handled.
##
## -PDB August 13, 2014
while self.estimation_thread.isrunning():
time.sleep(0.1)
## -PDB January 25, 2015


pr = self.pr.clone()
Expand All @@ -1180,14 +1186,17 @@ def perform_estimateNT(self):
if self.estimation_thread != None and self.estimation_thread.isrunning():
self.estimation_thread.stop()
## stop just raises the flag -- the thread is supposed to
## then kill itself but cannot. Paul Kienzle came up with
## this fix to prevent threads from stepping on each other
## in Calc1D of fitting.py which was causing a simple custom model
## to crash Sasview. See rest of notes under Calc1D.
## then kill itself. In August 2014 it was shown that this is
## incorrectly handled by fitting.py and a fix implemented.
## It is not clear whether it is properly used here, but the
## "fix" of waiting for the previous thread to end breaks the
## pr perspective completely as it causes an infinite loop.
## Thus it is likely the threading is bing properly handled.
## While the "fix" is no longer implemented the comment is
## left here till somebody ascertains that in fact the threads
## are being properly handled.
##
## -PDB August 13, 2014
while self.estimation_thread.isrunning():
time.sleep(0.1)
## -PDB January 25, 2015

pr = self.pr.clone()
# Skip the slit settings for the estimation
Expand Down
12 changes: 5 additions & 7 deletions src/sans/perspectives/simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,12 @@ def _simulate_Iq(self):
if self.calc_thread_1D != None and self.calc_thread_1D.isrunning():
self.calc_thread_1D.stop()
## stop just raises the flag -- the thread is supposed to
## then kill itself but cannot. Paul Kienzle came up with
## this fix to prevent threads from stepping on each other
## in Calc1D of fitting.py which was causing a simple custom model
## to crash Sasview. See rest of notes under Calc1D.
## then kill itself. In August 2014 it was shown that this is
## incorrectly handled by fitting.py and a fix implemented.
## It is not clear that it is improperly used here so no fix
## is being added here.
##
## -PDB August 13, 2014
while self.calc_thread_1D.isrunning():
time.sleep(0.1)
## -PDB January 25, 2015

# Create a computation thread
self.calc_thread_1D = Calc1D(self.x, self.volCanvas,
Expand Down

0 comments on commit f3efa09

Please sign in to comment.