Added check to ensure QThreads are finished before destroying them #245
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.