mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 18:07:44 +03:00 
			
		
		
		
	Implement thread-safety
This commit is contained in:
		
							parent
							
								
									b5ad081976
								
							
						
					
					
						commit
						650ee014ec
					
				| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,6 +163,7 @@ class Singleton(Provider):
 | 
			
		|||
 | 
			
		||||
    def _provide(self, *args, **kwargs):
 | 
			
		||||
        """Return provided instance."""
 | 
			
		||||
        with GLOBAL_LOCK:
 | 
			
		||||
            if not self._instance:
 | 
			
		||||
                self._instance = self._factory(*args, **kwargs)
 | 
			
		||||
        return self._instance
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,10 @@ Development version
 | 
			
		|||
 | 
			
		||||
- No featues.
 | 
			
		||||
 | 
			
		||||
0.9.3
 | 
			
		||||
-----
 | 
			
		||||
- Implement thread-safety.
 | 
			
		||||
 | 
			
		||||
0.9.2
 | 
			
		||||
-----
 | 
			
		||||
- 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 
 | 
			
		||||
custom providers.
 | 
			
		||||
 | 
			
		||||
All providers are validated in multithreading environment and considered to 
 | 
			
		||||
be thread-safe.
 | 
			
		||||
 | 
			
		||||
..  toctree::
 | 
			
		||||
    :maxdepth: 2
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user