mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-04-14 22:24:25 +03:00
Fix race in ThreadSafeSingleton (#322)
This commit is contained in:
parent
4120afd1c3
commit
fb0d99c1c9
|
@ -2178,15 +2178,19 @@ cdef class ThreadSafeSingleton(BaseSingleton):
|
|||
|
||||
:rtype: None
|
||||
"""
|
||||
self.__storage = None
|
||||
with self.__storage_lock:
|
||||
self.__storage = None
|
||||
|
||||
cpdef object _provide(self, tuple args, dict kwargs):
|
||||
"""Return single instance."""
|
||||
with self.__storage_lock:
|
||||
if self.__storage is None:
|
||||
self.__storage = __factory_call(self.__instantiator,
|
||||
args, kwargs)
|
||||
return self.__storage
|
||||
storage = self.__storage
|
||||
if storage is None:
|
||||
with self.__storage_lock:
|
||||
if self.__storage is None:
|
||||
self.__storage = __factory_call(self.__instantiator,
|
||||
args, kwargs)
|
||||
storage = self.__storage
|
||||
return storage
|
||||
|
||||
|
||||
cdef class DelegatedThreadSafeSingleton(ThreadSafeSingleton):
|
||||
|
|
Loading…
Reference in New Issue
Block a user