From a8ac78541a03fdecb13a6d51d3f3dfcb7161d230 Mon Sep 17 00:00:00 2001 From: Pierre Glaser Date: Tue, 4 Feb 2020 16:30:20 +0100 Subject: [PATCH] Add a test for #327 --- tests/cloudpickle_test.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 75655501b..724e9b9d1 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -108,6 +108,27 @@ def setUp(self): def tearDown(self): shutil.rmtree(self.tmpdir) + @pytest.mark.skipif( + sys.version_info >= (3, 8, 0) and sys.version_info < (3, 8, 2), + reason="Underlying bug fixed upstream starting Python3.8.2") + def test_reducer_override_reference_cycle(self): + # Early versions of Python3.8 introduced a reference cycle between a + # Pickler and it's reducer_override method. Because a Pickler + # object references every object it has pickled through its memo, this + # cycle prevented the garbage-collection of those external pickled + # objects. See #327 as well as https://bugs.python.org/issue39492 + # This bug was fixed in Python3.8.2, but is still present using + # cloudpickle and Python3.8.0/1, hence the skipif directive. + class MyClass: + pass + + my_object = MyClass() + wr = weakref.ref(my_object) + + cloudpickle.dumps(my_object) + del my_object + assert wr() is None, "'del'-ed my_object has not been collected" + def test_itemgetter(self): d = range(10) getter = itemgetter(1)