Пример #1
0
def test_inspect_serialization(enable_pickle_debug):
    import threading
    from ray.cloudpickle import dumps_debug

    lock = threading.Lock()

    with pytest.raises(TypeError):
        dumps_debug(lock)

    def test_func():
        print(lock)

    with pytest.raises(TypeError):
        dumps_debug(test_func)

    class test_class:
        def test(self):
            self.lock = lock

    from ray.util.check_serialize import inspect_serializability
    results = inspect_serializability(lock)
    assert list(results[1])[0].obj == lock, results

    results = inspect_serializability(test_func)
    assert list(results[1])[0].obj == lock, results

    results = inspect_serializability(test_class)
    assert list(results[1])[0].obj == lock, results
Пример #2
0
def dumps_debug(obj, *args, **kwargs):
    try:
        return dumps(obj, *args, **kwargs)
    except (TypeError, PicklingError) as exc:
        if os.environ.get("RAY_PICKLE_VERBOSE_DEBUG"):
            from ray.util.check_serialize import inspect_serializability
            inspect_serializability(obj)
            raise
        else:
            msg = _warn_msg(obj, "ray.cloudpickle.dumps", exc)
            raise type(exc)(msg)