fix: recreate process pool singleton on crash#903
Draft
Conversation
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Coverage ReportOverall Coverage: 91% Diff: origin/main...HEAD
Summary
Line-by-lineView line-by-line diff coveragelibs/core/kiln_ai/utils/pdf_utils.pyLines 21-34 21
22 def _reset_pdf_conversion_executor():
23 """Reset the PDF conversion executor, shutting down the old one if it exists."""
24 global _pdf_conversion_executor
! 25 if _pdf_conversion_executor is not None:
! 26 try:
! 27 _pdf_conversion_executor.shutdown(wait=False)
! 28 except Exception:
! 29 pass
! 30 _pdf_conversion_executor = None
31
32
33 # Lazy load for speed, singleton so dev-server reloading doesn't recreate the executor
34 def get_pdf_conversion_executor() -> ProcessPoolExecutor:Lines 94-114 94 pdf_path,
95 output_dir,
96 )
97 return result
! 98 except (BrokenExecutor, RuntimeError) as e:
! 99 error_msg = str(e).lower()
! 100 if (
101 "process pool" in error_msg
102 or "child process" in error_msg
103 or isinstance(e, BrokenExecutor)
104 ):
! 105 logger.warning(
106 f"Process pool became unusable, recreating executor. Error: {e}"
107 )
! 108 _reset_pdf_conversion_executor()
! 109 executor = get_pdf_conversion_executor()
! 110 result = await loop.run_in_executor(
111 executor,
112 _convert_pdf_to_images_sync,
113 pdf_path,
114 output_dir,Lines 112-121 112 _convert_pdf_to_images_sync,
113 pdf_path,
114 output_dir,
115 )
! 116 return result
! 117 raise
118
119
120 def _shutdown_pdf_conversion_executor():
121 """Shutdown the PDF conversion executor process."""
|
…ix-local-pdf-extraction-crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Local PDF processing sometimes fails - seems to be hardware dependent - and when that happens, the whole process pool that converts pages into images crashes.
Fix:
Checklists