File tree Expand file tree Collapse file tree 1 file changed +19
-10
lines changed
graalpython/lib-graalpython Expand file tree Collapse file tree 1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -41,19 +41,29 @@ class Context:
41
41
pass
42
42
43
43
44
+ _NO_DEFAULT = object ()
45
+
46
+
44
47
class ContextVar :
45
- def __init__ (self , name , default = None ):
48
+ def __init__ (self , name , default = _NO_DEFAULT ):
49
+ import threading
46
50
self ._name = name
47
- self ._value = default
48
-
49
- def get (self ):
50
- if self ._value is None :
51
+ self ._default = default
52
+ self ._local = threading .local ()
53
+
54
+ def get (self , default = _NO_DEFAULT ):
55
+ try :
56
+ return self ._local .value
57
+ except AttributeError :
58
+ if default is not _NO_DEFAULT :
59
+ return default
60
+ if self ._default is not _NO_DEFAULT :
61
+ return self ._default
51
62
raise LookupError
52
- return self ._value
53
-
63
+
54
64
def set (self , value ):
55
- self ._value = value
56
-
65
+ self ._local . value = value
66
+
57
67
def reset (self , token ):
58
68
pass
59
69
@@ -64,4 +74,3 @@ class Token:
64
74
65
75
def copy_context ():
66
76
raise NotImplementedError
67
-
You can’t perform that action at this time.
0 commit comments