-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-35715: Liberate return value of _process_worker #11514
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
Signed the PSF contributor agreement |
Lib/concurrent/futures/process.py
Outdated
@@ -239,6 +239,7 @@ def _process_worker(call_queue, result_queue, initializer, initargs): | |||
# Liberate the resource as soon as possible, to avoid holding onto | |||
# open files or shared memory that is not needed anymore | |||
del call_item | |||
del r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks incorrect as this will raise a NameError
if the first call to call_item
fails because the symbol was never bound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pablogsal thanks for catching that. I've modified to handle this case and do nothing - although I'm not generally a fan of pass
ing in except clauses it seems appropriate here.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Lib/concurrent/futures/process.py
Outdated
@@ -239,6 +239,10 @@ def _process_worker(call_queue, result_queue, initializer, initargs): | |||
# Liberate the resource as soon as possible, to avoid holding onto | |||
# open files or shared memory that is not needed anymore | |||
del call_item | |||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just need to delete the result in the else
clause of the previous try
block unless I am missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, thanks @pablogsal !
@pablogsal any other feedback on this one? |
Hey @pablogsal, any other feedback or changes needed here? |
Sorry for the delay. Please, ping me if I have not landed this this week :) |
@pablogsal did you mean to ping you about merging, or did I misunderstand? No need to apologise for the delay, appreciate you taking the time :) |
ProcessPoolExecutor workers will hold the return value of their last task in memory until the next task is received. Since the return value has already been propagated to the parent process's
Future
or else effectively discarded by this point, the memory can be safely released.Simple case to reproduce:
This should be easily addressed by having the worker explicitly
del r
after calling_sendback_result
as it already does this forcall_item
.https://bugs.python.org/issue35715