Skip to content

Offload blocking file conversion to threadpool (issue #5, Approach 1)#6

Merged
dezoito merged 1 commit into
mainfrom
claude/markitdown-issue-5-eval-0icdit
Jul 22, 2026
Merged

Offload blocking file conversion to threadpool (issue #5, Approach 1)#6
dezoito merged 1 commit into
mainfrom
claude/markitdown-issue-5-eval-0icdit

Conversation

@dezoito

@dezoito dezoito commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

The /process_file endpoint is async def, but convert_to_md() runs the synchronous MarkItDown().convert() call directly, blocking uvicorn's event loop for the entire conversion. While one file converts, the server cannot accept or respond to any other request.

This implements Approach 1 from #5: wrap the blocking call with FastAPI's run_in_threadpool, so the event loop stays free while the conversion runs on a worker thread.

Changes

  • Add from fastapi.concurrency import run_in_threadpool import.
  • Replace convert_to_md(temp_file_path) with await run_in_threadpool(convert_to_md, temp_file_path) in process_file.

Two-line diff; no changes to convert_to_md, error handling, or temp-file cleanup. Exceptions raised inside the threadpool still propagate through the await and are caught by the existing except block, and each call constructs its own MarkItDown instance, so there is no shared state across worker threads.

Verification

  • Module imports cleanly (python -c "import app").
  • Runtime smoke test: started uvicorn app:app on port 8490, POSTed a text file to /process_file, received 200 OK with the expected {"markdown": ...} payload; temp file cleanup logged as before.
  • Reviewed for exception propagation, cleanup ordering in finally, and thread safety — no blocking findings.

Notes

Approach 2 from the issue (AsyncOpenAI/_ocr_pdf rewrite) was intentionally not implemented — it references code that does not exist in this repository. For raw conversion throughput under heavy parallel load, the complementary lever is running multiple uvicorn workers; this change keeps each worker responsive.

Closes #5

🤖 Generated with Claude Code

https://claude.ai/code/session_018bkodLeWwRcswfSZNFo6Q3


Generated by Claude Code

…king, issue #5)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bkodLeWwRcswfSZNFo6Q3
@dezoito
dezoito merged commit 7da554b into main Jul 22, 2026
@dezoito

dezoito commented Jul 22, 2026

Copy link
Copy Markdown
Owner Author

Full hypocrisy alert, this PR was created by Claude after reviewing (and rightfully discarding) the suggestions made in issue #5 .

Garbage as that text was, Approach 1 made sense and was a simple enough change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make file conversion non-blocking (async)

2 participants