fix(async): chiamate bloccanti in asyncio.to_thread (#36 punto 1)
kaleido (pio.to_image), WeasyPrint (write_pdf), pdfplumber (extract_text_from_pdf) e la scrittura del CSV di produzione giravano sincrone dentro handler async: un PDF pesante o un run grande fermava il worker per tutte le altre richieste. Ora avvolte in await asyncio.to_thread(...) in report_service.py, ai_service.py e production_export_service.py. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""AI service for parsing technical sheets via OpenRouter."""
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
from io import BytesIO
|
||||
@@ -36,7 +37,9 @@ def extract_text_from_pdf(pdf_bytes: bytes) -> str:
|
||||
|
||||
|
||||
async def parse_technical_sheet(pdf_bytes: bytes) -> list[dict]:
|
||||
text = extract_text_from_pdf(pdf_bytes)
|
||||
# pdfplumber parses synchronously and can take a while on a big PDF: off
|
||||
# the event loop, or one upload stalls every other request being served.
|
||||
text = await asyncio.to_thread(extract_text_from_pdf, pdf_bytes)
|
||||
if not text.strip():
|
||||
return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user