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. - Easy, smart, pythonic style.
- Obvious, clear structure. - Obvious, clear structure.
- Memory efficiency. - Memory efficiency.
- Thread safety.
- Semantic versioning. - Semantic versioning.
Main idea of *Dependency Injector* is to keep dependencies under control. 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_attribute_injection
from .utils import is_method_injection from .utils import is_method_injection
from .utils import get_injectable_kwargs from .utils import get_injectable_kwargs
from .utils import GLOBAL_LOCK
from .errors import Error from .errors import Error
@ -162,8 +163,9 @@ class Singleton(Provider):
def _provide(self, *args, **kwargs): def _provide(self, *args, **kwargs):
"""Return provided instance.""" """Return provided instance."""
if not self._instance: with GLOBAL_LOCK:
self._instance = self._factory(*args, **kwargs) if not self._instance:
self._instance = self._factory(*args, **kwargs)
return self._instance return self._instance
def reset(self): def reset(self):

View File

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

View File

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

View File

@ -13,6 +13,10 @@ Development version
- No featues. - No featues.
0.9.3
-----
- Implement thread-safety.
0.9.2 0.9.2
----- -----
- Add minor refactorings. - 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 library and some useful information like overriding of providers and writing
custom providers. custom providers.
All providers are validated in multithreading environment and considered to
be thread-safe.
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2