-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Try deepcopy combine_fn and fallback to pickling if TypeError. #32645
base: master
Are you sure you want to change the base?
Conversation
Assigning reviewers. If you would like to opt out of this review, comment R: @liferoad for label python. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
# Deepcopy of the combine_fn to avoid sharing state between lifted | ||
# stages when using cloudpickle. | ||
try: | ||
self._combine_fn_copy = copy.deepcopy(combine_fn) |
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.
If we:
-
replace this line with
self._combine_fn_copy = pickler.loads(pickler.dumps(combine_fn)) -
use cloudpickle pickler
will we still hit https://github.com/apache/beam/issues/26209 ?
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.
No. The pickler.loads(pickler.dumps(a)) creates a deep copy of the instance a. For example
from apache_beam.internal import cloudpickle_pickler
class TestClass:
def __init__(self):
self._setup_called = False
def setup(self, *args, **kwargs):
assert not self._setup_called, 'setup should not be called twice'
self._setup_called = True
>>> original = TestClass()
>>> pickled_a = cloudpickle_pickler.loads(cloudpickle_pickler.dumps(original))
>>> pickled_b = cloudpickle_pickler.loads(cloudpickle_pickler.dumps(original))
>>> pickled_a == pickled_b
False
>>> pickled_a.setup()
>>> pickled_a._setup_called
True
>>> pickled_b.setup()
>>> pickled_a.setup()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 7, in setup
AssertionError: setup should not be called twice
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.
I can write a unit test for this scenario too
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.
except TypeError as e:
Can there be other errors? Let's catch all exceptions.
'Failed to copy combine function. Ensure python dependencies are'
' properly set up: %s'
I thought whether we should surface this, and I think this might create unactionable noise for the users. I wouldn't print anything if the copy, or copy via pickle was successful.
Roll forward with #32598 + fix the copy behavior if a module is being copied.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123
), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>
instead.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.