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
consider-using-with
on ThreadPoolExecutor?
#4689
Comments
Hello, I think we missed this use case. Do you think we should never raise this warning on |
I assumed that the intention is to encourage people to use the |
The main problem right now is, that the check can't detect if a context manager that was constructed earlier is subsequently used in a from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(4)
with executor:
# do something I will look into it as soon as possible. |
I fixed the check so that the message is only triggered if the created object is not subsequently used in a |
That check wouldn't actually fix the particular issue I'm facing, though. You don't generally do a bare
or you do:
I also suspect that the close of the |
Yep, I just checked: the Just because something declares |
I think it should go in 2.9.4 (if possible). If we have to wait so @fluffy-critter remarks are taken into account it can go in 2.10.x. |
In this case it's probably best to remove It seems to me like it is still best practice to call |
Yeah, it really comes down to the fact that there's different use cases for ThreadPoolExecutor and they have different patterns that make the most sense. Usually when I'm using it, it's for scheduling background tasks on a long-running persistent server process (basically in the same way one would use celery) and so there's never any reason for it to ever exit in the first place. |
Yes, you are right. Thanks for pointing that out, others would have probably run into the same issue! |
Question
It's pretty common to construct a
concurrent.futures.ThreadPoolExecutor
and keep it around as a singleton or a global variable or the like. Until recently this passed pylint just fine, but recently it's started giving me the error:Given that
ThreadPoolExecutor
typically is intended to sit around as a task queue that persists in the background, it seems strange for that one to be called out as a suggested use ofwith
. Is there a particular pattern I should be following, or is this just a case where I should be suppressing the warning on a case-by-case basis?The text was updated successfully, but these errors were encountered: