mirror of
https://github.com/wassname/ray.git
synced 2026-07-07 12:33:41 +08:00
Apply cpython patch bpo-39492 for the reference counting issue in pickle5 (#7177)
* apply cpython patch bpo-39492 for the reference count issue
This commit is contained in:
committed by
GitHub
parent
b6233dff3c
commit
6745459f96
@@ -10,6 +10,7 @@ import sys
|
||||
import threading
|
||||
import time
|
||||
import pickle
|
||||
import weakref
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@@ -453,6 +454,27 @@ def test_ray_recursive_objects(ray_start_regular):
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user