sharppy / SHARPpy

Sounding/Hodograph Analysis and Research Program in Python
https://sharppy.github.io/SHARPpy/index.html
Other
216 stars 112 forks source link

Added check to ensure QThreads are finished before destroying them #245

Open collin-volk opened 1 year ago

collin-volk commented 1 year ago

This is a fix for issue #244. In async_threads (and also async, although I couldn't find that being used anywhere) threads are destroyed in the finish slot of the AsyncThreads class. This slot is called when the finished signal is emitted by one of the threads at the end of their run function and leads to a race condition where the thread might not truly finish running before del is called on it. Adding a while loop checking the QThread isFinished function before destroying the thread ensures that the thread has actually finished running.

On a related note, QThread already has a finished signal that gets emitted when the thread actually finishes. Unfortunately, this signal doesn't include any information on what thread finished so it can't be used to perform the cleanup needed in AsyncThreads. In any case, it might be a good idea to rename the finished signal in AsyncThread to something like completed to avoid any confusion with the QThread finished signal.