mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-07 07:00:49 +03:00
Implement thread-safety
This commit is contained in:
parent
b5ad081976
commit
650ee014ec
|
@ -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.
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user