🕵️ SicherheitslückenCVE-2026-58728 | Google Android ARM64 MMU mmu.h ARM64_TLBI race condition(15.09.2026 um 21:40 Uhr)
🔧 ProgrammierungEnforce GitHub Advanced Security configurations(15.09.2026 um 21:31 Uhr)
🔧 ProgrammierungHow i give my coding agent a map of the repo with Empryo(15.09.2026 um 21:54 Uhr)
🔧 ProgrammierungReef Connects Agent Feedback, Learning and Versioned Delivery(15.09.2026 um 21:55 Uhr)
🔧 ProgrammierungUAJY Handbook RAG Chatbot Splits FAISS Search From Gemini(15.09.2026 um 21:55 Uhr)
🔧 ProgrammierungKnowledge Base For AI Agents: What It Must Do(15.09.2026 um 22:00 Uhr)
🕵️ SicherheitslückenCVE-2026-58728 | Google Android ARM64 MMU mmu.h ARM64_TLBI race condition(15.09.2026 um 21:40 Uhr)
🔧 ProgrammierungEnforce GitHub Advanced Security configurations(15.09.2026 um 21:31 Uhr)
🔧 ProgrammierungHow i give my coding agent a map of the repo with Empryo(15.09.2026 um 21:54 Uhr)
🔧 ProgrammierungReef Connects Agent Feedback, Learning and Versioned Delivery(15.09.2026 um 21:55 Uhr)
🔧 ProgrammierungUAJY Handbook RAG Chatbot Splits FAISS Search From Gemini(15.09.2026 um 21:55 Uhr)
🔧 ProgrammierungKnowledge Base For AI Agents: What It Must Do(15.09.2026 um 22:00 Uhr)

🔧 Programmierung 🕛 vor 3 Monaten 3 Min Lesezeit
0

From ThreadPoolExecutor to httpx AsyncClient: True Async Refactoring

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Published on: 2026-06-06


Reading time: 6 min


Tags: #python #async #performance #optimization





The Problem: Fake Async



The supabase-async library claimed to be async but actually wrapped synchronous calls with ThreadPoolExecutor:




CODE
# ❌ Fake async (old code)
class SupabaseAsync:
def __init__(self):
self._executor = ThreadPoolExecutor(max_workers=3)

async def select(self, table: str):
loop = asyncio.get_event_loop()
r = await loop.run_in_executor(
self._executor,
lambda: requests.get(url) # Sync call wrapped as async
)
return r.json()






Problems:




  1. Max 3 concurrent requests (not scalable)

  2. Thread overhead per request

  3. High memory usage

  4. No connection pooling






Solution: httpx AsyncClient



Use true async HTTP with httpx:




CODE
# ✅ Real async (new code)
import httpx

class SupabaseAsync:
def __init__(self):
self._client: Optional[httpx.AsyncClient] = None

async def _get_client(self) -> httpx.AsyncClient:
if self._client is None:
self._client = httpx.AsyncClient(
headers=self._headers,
timeout=30,
limits=httpx.Limits(max_connections=10)
)
return self._client

async def select(self, table: str):
client = await self._get_client()
r = await client.get(f"{self._base}/{table}")
r.raise_for_status()
return r.json()









Performance Gains

































Metric ThreadPoolExecutor(3) httpx(10)
Max concurrent 3 requests 10 requests
Avg response 450ms 150ms
Memory usage 250MB 180MB
Throughput 6.7 req/s 20 req/s


Real benchmark: 100 concurrent requests




  • ThreadPoolExecutor: 15 seconds

  • httpx AsyncClient: 5 seconds


  • 3x faster






Migration Steps






1. Client Initialization with Lazy Loading






CODE
async def _get_client(self) -> httpx.AsyncClient:
if self._client is None:
self._client = httpx.AsyncClient(
headers=self._headers,
timeout=30,
limits=httpx.Limits(
max_connections=10,
max_keepalive_connections=5
)
)
return self._client









2. HTTP Methods (GET, POST, etc.)






CODE
async def _request(self, method: str, url: str, **kwargs):
client = await self._get_client()
if method == "GET":
return await client.get(url, **kwargs)
elif method == "POST":
return await client.post(url, **kwargs)
# ... more methods









3. Context Manager Support






CODE
async def close(self):
if self._client:
await self._client.aclose()

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.close()

# Usage
async with SupabaseAsync(url, key) as db:
results = await db.select("contests")









Production Results



After deploying to contest-agent (FastAPI on Cloud Run):




CODE
Response time: 450ms → 150ms (3x faster)
Memory: 250MB → 180MB (28% reduction)
Concurrent capacity: 3 → 10 (3.3x increase)









Key Differences






































Aspect ThreadPoolExecutor httpx
Type Thread pool + sync I/O True async I/O
Concurrency Limited by thread count Limited by system resources
Memory Thread overhead per request Minimal overhead
Connection pooling Manual Automatic
Learning curve Easy (familiar pattern) Moderate (async patterns)





Migration Cautions





  1. Exception types change: requests.HTTPErrorhttpx.HTTPError


  2. Connection pooling is automatic: Don't manually manage connections


  3. Timeout behavior: Slightly different, but compatible






Lessons



ThreadPoolExecutor is a band-aid. For truly async I/O:




  • Use real async HTTP clients (httpx, aiohttp)

  • Understand async/await patterns

  • Design from async-first perspective



This is especially critical for:




  • High-concurrency services (web crawlers, API gateways)

  • Limited resources (serverless, microservices)

  • Real-time applications






Conclusion



Going from fake async to true async isn't just a performance win—it's a design improvement. You get:




  • 3x faster response times

  • 30% memory savings

  • Unlimited concurrency (within reason)

  • Proper resource management



If your async code uses ThreadPoolExecutor or loop.run_in_executor, refactor it now.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
CVE-2026-58728 | Google Android ARM64 MMU mmu.h ARM64_TLBI race condition
1 Quelle
DFN-CERT-2026-4853 Xcode: Eine Schwachstelle ermöglicht das Ausspähen von Informationen
1 Quelle
Enforce GitHub Advanced Security configurations
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten From ThreadPoolExecutor to httpx AsyncClient: True Async Refactoring

Thematisch verwandte Begriffe: From, ThreadPoolExecutor, httpx, AsyncClient · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...