Skip to content

Move Docling converter.convert() to run_in_executor for async safety #16

Description

@ayushpahwa

Context

The DoclingExtractionProvider.extract() method calls self.converter.convert() which is a synchronous, CPU-heavy operation (ML-based PDF parsing). This blocks the FastAPI event loop and would degrade performance under concurrent requests.

Flagged by Copilot review on PR #15.

Current state

Not an issue right now — this is a single-user local service. The 5MB file size limit also bounds the processing time.

Proposed fix

Wrap the blocking call with run_in_executor:

import asyncio

loop = asyncio.get_event_loop()
result = await loop.run_in_executor(None, self.converter.convert, stream)

When to address

When the service needs to handle concurrent requests or moves beyond single-user local use.

Location

src/pdf-parse/app/services/docling.pyDoclingExtractionProvider.extract() method

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions