Fix _QThreadWorker.run not releasing references to fulfilled command object before blocking on next queue.get call #113
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.
When writing tests, I've noticed that when using
qasync.QThreadExecutor
, the objects, be it instance method owners, or something passed in as args, were not deleted immediately as the executor finished running the submitted task, even if there were no more references to those objects on the user side. The only way to release them was either to submit a new task, or shutdown an executor.While investigating the code, I've also taken a look into
concurrent.futures.ThreadPoolExecutor
, which didn't exhibit this behaviour.That's where I found the following code:
This PR mimics this change by adding a manual deletion of references to command tuple and its inner parameters inside of
_QThreadWorker.run
;The change can be tested by running the following example:
Before:
After:
As for potential downsides of this change: there could theoretically be code that accidentally relies on QThreadExecutor not releasing references, especially if QObject, Slots and other Qt-related stuff is involved.
But even if it's a big issue, it still might be worth adding an option to enable proper behaviour via an environment variable or other parameter.