@@ -47,6 +47,11 @@ def _trace(boolean):
47
47
from _thread import RLock as RLockType
48
48
else :
49
49
from threading import _RLock as RLockType
50
+ # monkey patch for _thread._local
51
+ try :
52
+ from _thread import _local as LocalType
53
+ except ImportError :
54
+ from _threading_local import local as LocalType
50
55
#from io import IOBase
51
56
from types import CodeType , FunctionType , MethodType , GeneratorType , \
52
57
TracebackType , FrameType , ModuleType , BuiltinMethodType
@@ -85,7 +90,7 @@ def _trace(boolean):
85
90
FileNotFoundError = IOError
86
91
if PY3 and sys .hexversion < 0x03040000 :
87
92
GENERATOR_FAIL = True
88
- else : GENERATOR_FAIL = False
93
+ else : GENERATOR_FAIL = False
89
94
try :
90
95
import ctypes
91
96
HAS_CTYPES = True
@@ -596,6 +601,13 @@ def _create_ftype(ftypeobj, func, args, kwds):
596
601
args = ()
597
602
return ftypeobj (func , * args , ** kwds )
598
603
604
+ def _create_local (impl , * args , ** kwargs ): #XXX: ignores 'blocking'
605
+ local = LocalType ()
606
+ if local :
607
+ if impl :
608
+ local .__setattr__ ('_local__impl' , impl )
609
+ return local
610
+
599
611
def _create_lock (locked , * args ): #XXX: ignores 'blocking'
600
612
from threading import Lock
601
613
lock = Lock ()
@@ -927,6 +939,23 @@ def save_classobj(pickler, obj): #FIXME: enable pickler._byref
927
939
log .info ("# C2" )
928
940
return
929
941
942
+ @register (LocalType )
943
+ def save_local (pickler , obj ):
944
+ log .info ("Loc: %s" % obj )
945
+ impl = obj .__getattribute__ ('_local__impl' )
946
+ if impl :
947
+ try :
948
+ dct = impl .get_dict ()
949
+ except KeyError :
950
+ dct = impl .create_dict ()
951
+ args , kwargs = impl .localargs
952
+ obj .__init__ (* args , ** kwargs )
953
+ with impl .locallock :
954
+ obj .__setattr__ ('__dict__' , dct )
955
+ pickler .save_reduce (_create_local , (impl ,), obj = obj )
956
+ log .info ("# Loc" )
957
+ return
958
+
930
959
@register (LockType )
931
960
def save_lock (pickler , obj ):
932
961
log .info ("Lo: %s" % obj )
0 commit comments