You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
or [Storage][health_check.checks.Storage]) in a thread pool.
155
+
This pool is usually persisted across requests. This may lead to high performance while
156
+
permanently allocating more memory. This may be undesirable for some applications,
157
+
especially with `S3Storage`, which uses thread-local connections.
158
+
159
+
This can be mitigated by using a custom executor that creates a new thread pool for each request, which is then cleaned up after the checks are completed. This can be achieved by subclassing `HealthCheckView` and overriding the `get_executor` method to return a new `ThreadPoolExecutor` instance for each request.
160
+
161
+
```python
162
+
from concurrent.futures import ThreadPoolExecutor
163
+
from health_check.views import HealthCheckView
164
+
165
+
166
+
classCustomHealthCheckView(HealthCheckView):
167
+
@staticmethod
168
+
defget_executor(self):
169
+
with ThreadPoolExecutor(max_workers=len(self.checks)) as executor:
170
+
yield executor
171
+
```
172
+
173
+
This approach ensures that each request gets a fresh thread pool,
174
+
which can help manage memory usage more effectively
175
+
while still providing the benefits of concurrent execution for synchronous checks.
0 commit comments