Replies: 3 comments 2 replies
-
Agreed, if you notice anything else, please let me know. I will make those changes as part of the pull request for #140. Also, @lesnik512 I have already migrated a larger application to the pre-release version and haven't had any issues. However, keep in mind that that app does not make use of the |
Beta Was this translation helpful? Give feedback.
-
See #143 (Work in progress) |
Beta Was this translation helpful? Give feedback.
-
Okay there is actually a large issue on the pre-release version Here was my first example to reproduce: # app.py
from that_depends import providers
from that_depends import BaseContainer, container_context, inject, Provide
import uvicorn
app = FastAPI()
async def async_creator() -> typing.Iterator[str]:
try:
await asyncio.sleep(1)
yield str(uuid4())
finally:
print("Tearing down")
class MyContainer(BaseContainer):
my_async_context_resource = providers.ContextResource(async_creator)
async def init_container_context():
async with container_context(MyContainer):
yield
router = APIRouter(dependencies=[Depends(init_container_context)])
@container_context()
@inject
async def injected(val: str = Provide[MyContainer.my_async_context_resource]) -> str:
return val
@router.get("/")
async def read_root():
return await injected()
app.include_router(router)
if __name__ == "__main__":
uvicorn.run("test:app", port=8008, reload=True) # stress_test.py
import threading
import requests
# Define the target endpoint and the payload
endpoint = "http://localhost:8008/"
# Function to send a single request
def send_request():
try:
response = requests.get(endpoint)
print(f"Response Code: {response.status_code}, Response Body: {response.text}")
except Exception as e:
print(f"Request failed: {e}")
if __name__ == '__main__':
# Create and start multiple threads
num_threads = 50 # Number of simultaneous requests
threads = []
for _ in range(num_threads):
thread = threading.Thread(target=send_request)
threads.append(thread)
thread.start()
# Wait for all threads to finish
for thread in threads:
thread.join() Long story short, this causes a |
Beta Was this translation helpful? Give feedback.
-
@vrslev Raised some questions. @alexanderlazarev0 Let's discuss them, before releasing as 2.0.0
In new design default value of reset_all_containers is False in container_context, while in DIContextMiddleware it's True. Maybe make them consistent?
Beta Was this translation helpful? Give feedback.
All reactions