File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -73,13 +73,17 @@ class ThreadVigil(object):
73
73
pass
74
74
75
75
def _make_vigil (self ):
76
- # Assigning to a threadlocal isn't thread-safe in Python <= 2.7.0
76
+ # Threadlocals in Python <= 2.7.0 have race conditions when setting
77
+ # attributes and possibly when getting them, too, leading to weakref
78
+ # callbacks not getting called later.
77
79
self ._lock .acquire ()
78
- vigil = getattr (self ._local , 'vigil' , None )
79
- if not vigil :
80
- self ._local .vigil = vigil = ThreadIdent .ThreadVigil ()
80
+ try :
81
+ vigil = getattr (self ._local , 'vigil' , None )
82
+ if not vigil :
83
+ self ._local .vigil = vigil = ThreadIdent .ThreadVigil ()
84
+ finally :
85
+ self ._lock .release ()
81
86
82
- self ._lock .release ()
83
87
return vigil
84
88
85
89
def get (self ):
You can’t perform that action at this time.
0 commit comments