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):
7373 pass
7474
7575 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.
7779 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 ()
8186
82- self ._lock .release ()
8387 return vigil
8488
8589 def get (self ):
You can’t perform that action at this time.
0 commit comments