6_Month_Visit using POST API

This commit is contained in:
2026-02-03 20:54:54 +01:00
parent 8478604103
commit 0e842eb0fb
12 changed files with 536 additions and 229700 deletions

View File

@@ -21,9 +21,12 @@ from eb_dashboard_constants import CONFIG_FOLDER_NAME
# ============================================================================
# GLOBAL VARIABLES (managed by main module)
# ============================================================================
thread_local_storage = threading.local()
# These will be set/accessed from the main module
httpx_clients = {}
_clients_lock = threading.Lock()
threads_list = []
_threads_list_lock = threading.Lock()
@@ -34,19 +37,37 @@ _threads_list_lock = threading.Lock()
def get_httpx_client() -> httpx.Client:
"""
Get or create thread-local HTTP client with keep-alive enabled.
Each thread gets its own httpx.Client instance to avoid connection conflicts.
Keep-alive connections improve performance by reusing TCP connections.
Get or create thread-local HTTP client.
Keep-alive is disabled to avoid stale connections with load balancers.
"""
global httpx_clients
thread_id = threading.get_ident()
if thread_id not in httpx_clients:
# Create client with keep-alive headers and connection pooling
httpx_clients[thread_id] = httpx.Client(
headers={"Connection": "keep-alive"},
limits=httpx.Limits(max_keepalive_connections=20, max_connections=100)
)
return httpx_clients[thread_id]
with _clients_lock:
if thread_id not in httpx_clients:
# Create client with keep-alive disabled
httpx_clients[thread_id] = httpx.Client(
headers={"Connection": "close"}, # Explicitly request closing
limits=httpx.Limits(max_keepalive_connections=0, max_connections=100)
)
return httpx_clients[thread_id]
def clear_httpx_client():
"""
Removes the current thread's client from the cache.
Ensures a fresh client (and socket pool) will be created on the next call.
"""
global httpx_clients
thread_id = threading.get_ident()
with _clients_lock:
if thread_id in httpx_clients:
try:
# Close the client before removing it
httpx_clients[thread_id].close()
except:
pass
del httpx_clients[thread_id]
def get_thread_position():