New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Threads leaked if executor is not shut down #87
Comments
rohanpm
added a commit
that referenced
this issue
Dec 26, 2018
Threads should hold only weak references to their executors and should exit once the reference is lost. This allows threads to be cleaned up even if shutdown() is never called on an executor. Fixes #87
bors bot
added a commit
that referenced
this issue
Dec 26, 2018
88: Avoid thread leaks when shutdown() is not called r=rohanpm a=rohanpm Threads should hold only weak references to their executors and should exit once the reference is lost. This allows threads to be cleaned up even if shutdown() is never called on an executor. Fixes #87 Co-authored-by: Rohan McGovern <rohan@mcgovern.id.au>
rohanpm
added a commit
that referenced
this issue
Dec 26, 2018
Threads should hold only weak references to their executors and should exit once the reference is lost. This allows threads to be cleaned up even if shutdown() is never called on an executor. Fixes #87
bors bot
added a commit
that referenced
this issue
Dec 26, 2018
88: Avoid thread leaks when shutdown() is not called r=rohanpm a=rohanpm Threads should hold only weak references to their executors and should exit once the reference is lost. This allows threads to be cleaned up even if shutdown() is never called on an executor. Fixes #87 Co-authored-by: Rohan McGovern <rohan@mcgovern.id.au>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The RetryExecutor and probably some others will leak threads if the executor is not shut down. Although it could be argued that the caller should shut down the executor, the concurrent.futures ThreadPoolExecutor manages to clean up threads without requiring a shut down, and it would be convenient if that worked for all of our executors too.
Demo script here: https://gist.github.com/rohanpm/117dd79f7fa1e806f721e54d66f67773
Produces output:
With ThreadPoolExecutor alone, or with ThreadPool & retry & shutdown, threads created by the executors disappear. However, if retry is used and shutdown is not used, threads remain alive forever.
The ThreadPoolExecutor implementation shows careful usage of weakref allowing the executor to be collected while the threads are running. Presumably same approach should be used for all cases where our executors create threads.
The text was updated successfully, but these errors were encountered: