Skip to content
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

Apply cpython patch bpo-39492 for the reference counting issue in pickle5 #7177

Merged
merged 4 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ WORK_DIR=`mktemp -d`
pushd $WORK_DIR
git clone https://github.com/suquark/pickle5-backport
pushd pickle5-backport
git checkout 43551fbb9add8ac2e8551b96fdaf2fe5a3b5997d
git checkout 8ffe41ceba9d5e2ce8a98190f6b3d2f3325e5a72
"$PYTHON_EXECUTABLE" setup.py bdist_wheel
unzip -o dist/*.whl -d "$ROOT_DIR/python/ray/pickle5_files"
popd
Expand Down
22 changes: 22 additions & 0 deletions python/ray/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import threading
import time
import pickle
import weakref

import numpy as np
import pytest
Expand Down Expand Up @@ -453,6 +454,27 @@ class ClassA:
ray.put(obj)


def test_reducer_override_no_reference_cycle(ray_start_regular):
# bpo-39492: reducer_override used to induce a spurious reference cycle
# inside the Pickler object, that could prevent all serialized objects
# from being garbage-collected without explicity invoking gc.collect.
f = lambda: 4669201609102990671853203821578

wr = weakref.ref(f)

bio = io.BytesIO()
from ray.cloudpickle import CloudPickler, loads
p = CloudPickler(bio, protocol=5)
p.dump(f)
new_f = loads(bio.getvalue())
assert new_f() == 4669201609102990671853203821578

del p
del f

assert wr() is None


def test_passing_arguments_by_value_out_of_the_box(ray_start_regular):
@ray.remote
def f(x):
Expand Down