You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by ro...@apache.org on 2016/07/12 16:23:51 UTC

[1/2] incubator-beam git commit: Closes #629

Repository: incubator-beam
Updated Branches:
  refs/heads/python-sdk 4006f7779 -> fb9da8e32


Closes #629


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/fb9da8e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/fb9da8e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/fb9da8e3

Branch: refs/heads/python-sdk
Commit: fb9da8e32d432b67954ce37732aa27c56b2061ff
Parents: 4006f77 4e2d8ab
Author: Robert Bradshaw <ro...@google.com>
Authored: Tue Jul 12 09:22:43 2016 -0700
Committer: Robert Bradshaw <ro...@google.com>
Committed: Tue Jul 12 09:22:43 2016 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/internal/pickler.py      | 18 ++++++++++++++++++
 sdks/python/apache_beam/internal/pickler_test.py |  3 +++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------



[2/2] incubator-beam git commit: Pickle only used symbols from __main__ namespace.

Posted by ro...@apache.org.
Pickle only used symbols from __main__ namespace.


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/4e2d8ab2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/4e2d8ab2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/4e2d8ab2

Branch: refs/heads/python-sdk
Commit: 4e2d8ab2f4b33793bce2decc18ad817716ae5de0
Parents: 4006f77
Author: Robert Bradshaw <ro...@google.com>
Authored: Mon Jul 11 14:06:39 2016 -0700
Committer: Robert Bradshaw <ro...@google.com>
Committed: Tue Jul 12 09:22:43 2016 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/internal/pickler.py      | 18 ++++++++++++++++++
 sdks/python/apache_beam/internal/pickler_test.py |  3 +++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/4e2d8ab2/sdks/python/apache_beam/internal/pickler.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/internal/pickler.py b/sdks/python/apache_beam/internal/pickler.py
index 898e04b..f427aa5 100644
--- a/sdks/python/apache_beam/internal/pickler.py
+++ b/sdks/python/apache_beam/internal/pickler.py
@@ -159,6 +159,24 @@ if 'save_module' in dir(dill.dill):
       return old_save_module_dict(pickler, obj)
   dill.dill.save_module_dict = new_save_module_dict
 
+
+  old_save_function = dill.dill.save_function
+
+  @dill.dill.register(types.FunctionType)
+  def new_save_function(pickler, obj):
+    globs = obj.__globals__ if dill.dill.PY3 else obj.func_globals
+    if (dill.dill.is_dill(pickler) and globs == pickler._main.__dict__
+        and not pickler._recurse):
+      try:
+        pickler._recurse = True
+        return old_save_function(pickler, obj)
+      finally:
+        pickler._recurse = False
+    else:
+      return old_save_function(pickler, obj)
+  dill.dill.save_function = new_save_function
+
+
   def _nest_dill_logging():
     """Prefix all dill logging with its depth in the callstack.
 

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/4e2d8ab2/sdks/python/apache_beam/internal/pickler_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/internal/pickler_test.py b/sdks/python/apache_beam/internal/pickler_test.py
index 20de923..bd59c73 100644
--- a/sdks/python/apache_beam/internal/pickler_test.py
+++ b/sdks/python/apache_beam/internal/pickler_test.py
@@ -40,6 +40,9 @@ class PicklerTest(unittest.TestCase):
         ['abc', 'def'],
         loads(dumps(module_test.get_lambda_with_globals()))('abc def'))
 
+  def test_lambda_with_main_globals(self):
+    self.assertEquals(unittest, loads(dumps(lambda : unittest))())
+
   def test_lambda_with_closure(self):
     """Tests that the closure of a function is preserved."""
     self.assertEquals(