@@ -94,7 +94,10 @@ def run(self) -> None:
9494 method = getattr (self ._fitter , self ._method_name )
9595 result = method (* self ._args , ** self ._kwargs )
9696
97- # Check if stop was requested during execution
97+ # NOTE: This check only catches stop requests that occurred AFTER the fit
98+ # completed but before we emit the result. It does NOT interrupt the fitting
99+ # algorithm mid-execution since lmfit/scipy don't support cancellation callbacks.
100+ # The effective cancellation window is only before the fit starts (checked above).
98101 if self ._stop_requested :
99102 self .failed .emit ('Fitting cancelled by user' )
100103 return
@@ -119,9 +122,26 @@ def stop(self) -> None:
119122 This sets a flag that is checked during execution and also
120123 terminates the thread if it's still running. Call wait() after
121124 this to ensure proper thread cleanup.
125+
126+ .. warning::
127+ DANGEROUS: This method uses QThread.terminate() which is strongly
128+ discouraged by Qt documentation. It can:
129+ - Leave mutex locks held indefinitely causing deadlocks
130+ - Corrupt data structures mid-operation
131+ - Prevent proper cleanup of resources (especially numpy arrays, scipy internals)
132+ - Cause memory leaks and undefined behavior
133+
134+ The fitting libraries (lmfit, scipy) do not support graceful cancellation.
135+ The stop flag is only effective BEFORE the fit starts - once the fitting
136+ algorithm is running, it cannot be interrupted cleanly.
137+
138+ See THREAD_TERMINATION_WARNING.md for details on known issues and
139+ potential future improvements (e.g., using subprocess instead of QThread).
122140 """
123141 self ._stop_requested = True
124142 if self .isRunning ():
143+ # WARNING: terminate() is dangerous but necessary since fitting
144+ # libraries don't support graceful cancellation. See docstring above.
125145 self .terminate ()
126146 self .wait ()
127147
0 commit comments