mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 09:57:37 +03:00 
			
		
		
		
	Update resource docs
This commit is contained in:
		
							parent
							
								
									9a43ee7e88
								
							
						
					
					
						commit
						d8bb4a3bd8
					
				| 
						 | 
				
			
			@ -98,7 +98,7 @@ you configure global resource:
 | 
			
		|||
 | 
			
		||||
       configure_logging = providers.Resource(
 | 
			
		||||
           logging.config.fileConfig,
 | 
			
		||||
           fname='logging.ini',
 | 
			
		||||
           fname="logging.ini",
 | 
			
		||||
       )
 | 
			
		||||
 | 
			
		||||
Function initializer does not provide a way to specify custom resource shutdown.
 | 
			
		||||
| 
						 | 
				
			
			@ -210,8 +210,8 @@ first argument.
 | 
			
		|||
 | 
			
		||||
.. _resource-provider-wiring-closing:
 | 
			
		||||
 | 
			
		||||
Resources, wiring and per-function execution scope
 | 
			
		||||
--------------------------------------------------
 | 
			
		||||
Resources, wiring, and per-function execution scope
 | 
			
		||||
---------------------------------------------------
 | 
			
		||||
 | 
			
		||||
You can compound ``Resource`` provider with :ref:`wiring` to implement per-function
 | 
			
		||||
execution scope. For doing this you need to use additional ``Closing`` marker from
 | 
			
		||||
| 
						 | 
				
			
			@ -220,7 +220,7 @@ execution scope. For doing this you need to use additional ``Closing`` marker fr
 | 
			
		|||
.. literalinclude:: ../../examples/wiring/flask_resource_closing.py
 | 
			
		||||
   :language: python
 | 
			
		||||
   :lines: 3-
 | 
			
		||||
   :emphasize-lines: 24
 | 
			
		||||
   :emphasize-lines: 22
 | 
			
		||||
 | 
			
		||||
Framework initializes and injects the resource into the function. With the ``Closing`` marker
 | 
			
		||||
framework calls resource ``shutdown()`` method when function execution is over.
 | 
			
		||||
| 
						 | 
				
			
			@ -325,7 +325,7 @@ When you use resource provider with asynchronous initializer you need to call it
 | 
			
		|||
       connection = await container.connection.shutdown()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   if __name__ == '__main__':
 | 
			
		||||
   if __name__ == "__main__":
 | 
			
		||||
       asyncio.run(main())
 | 
			
		||||
 | 
			
		||||
Container ``init_resources()`` and ``shutdown_resources()`` methods should be used asynchronously if there is
 | 
			
		||||
| 
						 | 
				
			
			@ -349,7 +349,7 @@ at least one asynchronous resource provider:
 | 
			
		|||
       await container.shutdown_resources()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
   if __name__ == '__main__':
 | 
			
		||||
   if __name__ == "__main__":
 | 
			
		||||
       asyncio.run(main())
 | 
			
		||||
 | 
			
		||||
See also:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,12 +29,12 @@ class Container(containers.DeclarativeContainer):
 | 
			
		|||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    container = Container(config={'max_workers': 4})
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    container = Container(config={"max_workers": 4})
 | 
			
		||||
 | 
			
		||||
    container.init_resources()
 | 
			
		||||
 | 
			
		||||
    logging.info('Resources are initialized')
 | 
			
		||||
    logging.info("Resources are initialized")
 | 
			
		||||
    thread_pool = container.thread_pool()
 | 
			
		||||
    thread_pool.map(print, range(10))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user