|
@@ -8,6 +8,7 @@ import functools
|
|
|
import json
|
|
|
import os
|
|
|
import sys
|
|
|
+import threading
|
|
|
from textwrap import dedent
|
|
|
from typing import Any, AsyncGenerator, Callable, Dict, List, Optional, Union
|
|
|
from unittest.mock import AsyncMock, Mock
|
|
@@ -3390,9 +3391,15 @@ def test_fallback_pickle():
|
|
|
assert unpickled_state._f() == 420
|
|
|
assert unpickled_state._o._f() == 42
|
|
|
|
|
|
+ # Threading locks are unpicklable normally, and raise TypeError instead of PicklingError.
|
|
|
+ state2 = DillState(_reflex_internal_init=True) # type: ignore
|
|
|
+ state2._g = threading.Lock()
|
|
|
+ pk2 = state2._serialize()
|
|
|
+ unpickled_state2 = BaseState._deserialize(pk2)
|
|
|
+ assert isinstance(unpickled_state2._g, type(threading.Lock()))
|
|
|
+
|
|
|
# Some object, like generator, are still unpicklable with dill.
|
|
|
- state._g = (i for i in range(10))
|
|
|
- pk = state._serialize()
|
|
|
- assert len(pk) == 0
|
|
|
- with pytest.raises(EOFError):
|
|
|
- BaseState._deserialize(pk)
|
|
|
+ state3 = DillState(_reflex_internal_init=True) # type: ignore
|
|
|
+ state3._g = (i for i in range(10))
|
|
|
+ pk3 = state3._serialize()
|
|
|
+ assert len(pk3) == 0
|