Implement thread-safety

This commit is contained in:
Roman Mogilatov 2015-09-04 02:33:15 +03:00
parent b5ad081976
commit 650ee014ec
7 changed files with 19 additions and 3 deletions

View File

@ -39,6 +39,7 @@ framework:
- Easy, smart, pythonic style.
- Obvious, clear structure.
- Memory efficiency.
- Thread safety.
- Semantic versioning.
Main idea of *Dependency Injector* is to keep dependencies under control.

View File

@ -1 +1 @@
0.9.2
0.9.3

View File

@ -9,6 +9,7 @@ from .utils import is_kwarg_injection
from .utils import is_attribute_injection
from .utils import is_method_injection
from .utils import get_injectable_kwargs
from .utils import GLOBAL_LOCK
from .errors import Error
@ -162,8 +163,9 @@ class Singleton(Provider):
def _provide(self, *args, **kwargs):
"""Return provided instance."""
if not self._instance:
self._instance = self._factory(*args, **kwargs)
with GLOBAL_LOCK:
if not self._instance:
self._instance = self._factory(*args, **kwargs)
return self._instance
def reset(self):

View File

@ -1,10 +1,15 @@
"""Utils module."""
import threading
import six
from .errors import Error
GLOBAL_LOCK = threading.RLock()
def is_provider(instance):
"""Check if instance is provider instance."""
return (not isinstance(instance, six.class_types) and

View File

@ -39,6 +39,7 @@ framework:
- Easy, smart, pythonic style.
- Obvious, clear structure.
- Memory efficiency.
- Thread safety.
- Semantic versioning.
Main idea of *Dependency Injector* is to keep dependencies under control.

View File

@ -13,6 +13,10 @@ Development version
- No featues.
0.9.3
-----
- Implement thread-safety.
0.9.2
-----
- Add minor refactorings.

View File

@ -12,6 +12,9 @@ Current documentation section consists from description of standard providers
library and some useful information like overriding of providers and writing
custom providers.
All providers are validated in multithreading environment and considered to
be thread-safe.
.. toctree::
:maxdepth: 2