Skip to content

Commit 4f97ad9

Browse files
authored
Use internal DEFAULT_PICKLE_LIB (#37052)
* Use internal DEFAULT_PICKLE_LIB * Enable only on Dataflow
1 parent c65c198 commit 4f97ad9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

sdks/python/apache_beam/options/pipeline_options.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,15 +1682,16 @@ def _add_argparse_args(cls, parser):
16821682
'defined in __main__ (e.g. interactive session) can be unpickled. '
16831683
'Some workflows do not need the session state if for instance all '
16841684
'their functions/classes are defined in proper modules '
1685-
'(not __main__) and the modules are importable in the worker. '))
1685+
'(not __main__) and the modules are importable in the worker. '
1686+
'It is disabled by default except for cloudpickle as pickle '
1687+
'library on Dataflow runner.'))
16861688
parser.add_argument(
16871689
'--no_save_main_session',
16881690
default=None,
16891691
action='store_false',
16901692
dest='save_main_session',
16911693
help=(
1692-
'Disable saving the main session state. It is enabled/disabled by'
1693-
'default for cloudpickle/dill pickler. See "save_main_session".'))
1694+
'Disable saving the main session state. See "save_main_session".'))
16941695

16951696
parser.add_argument(
16961697
'--sdk_location',
@@ -1795,13 +1796,19 @@ def _add_argparse_args(cls, parser):
17951796
def _handle_load_main_session(self, validator):
17961797
save_main_session = getattr(self, 'save_main_session')
17971798
if save_main_session is None:
1798-
# save_main_session default to False for dill, while default to true
1799-
# for cloudpickle
1800-
pickle_library = getattr(self, 'pickle_library')
1801-
if pickle_library in ['default', 'cloudpickle']:
1802-
setattr(self, 'save_main_session', True)
1803-
else:
1799+
if not validator.is_service_runner():
18041800
setattr(self, 'save_main_session', False)
1801+
else:
1802+
# save_main_session default to False for dill, while default to true
1803+
# for cloudpickle on service runner
1804+
pickle_library = getattr(self, 'pickle_library')
1805+
if pickle_library == 'default':
1806+
from apache_beam.internal.pickler import DEFAULT_PICKLE_LIB
1807+
pickle_library = DEFAULT_PICKLE_LIB
1808+
if pickle_library == 'cloudpickle':
1809+
setattr(self, 'save_main_session', True)
1810+
else:
1811+
setattr(self, 'save_main_session', False)
18051812
return []
18061813

18071814
def validate(self, validator):

0 commit comments

Comments
 (0)