3333from rovr .functions import path as path_utils
3434from rovr .functions import preview_utils
3535from rovr .functions .pdf import get_pdf_images , get_pdf_info
36- from rovr .functions .utils import should_cancel
36+ from rovr .functions .preview_utils import (
37+ load_svg_sync ,
38+ resample_batch_sync ,
39+ resample_file_sync ,
40+ resample_sync ,
41+ )
42+ from rovr .functions .utils import multiprocessing_process_error_checker , should_cancel
3743from rovr .variables .constants import PreviewContainerTitles , config , file_one
3844from rovr .widgets import Static
3945
@@ -313,15 +319,28 @@ def show_font_preview(self) -> None:
313319 return
314320
315321 def show_resvg_preview (self ) -> None :
316- """Show svg preview using resvg"""
322+ """Show svg preview using resvg.
323+
324+ Raises:
325+ ValueError: If SVG loading fails for non-fds_to_keep reasons.
326+ """
317327 if should_cancel () or self ._current_file_path is None :
318328 return
319329 self .app .call_from_thread (setattr , self , "border_title" , titles .svg )
320330
321331 # load svg as bytes
322332 try :
323333 self .call_next (self .LOADER_WIDGET .update , "loading svg..." )
324- png_bytes = preview_utils .load_svg (self ._current_file_path )
334+ if self .app .MULTIPROCESSING_PROCESS_ALLOWED :
335+ try :
336+ png_bytes = preview_utils .load_svg (self ._current_file_path )
337+ except ValueError as exc :
338+ if multiprocessing_process_error_checker (self .app , exc ):
339+ png_bytes = load_svg_sync (self ._current_file_path )
340+ else :
341+ raise
342+ else :
343+ png_bytes = load_svg_sync (self ._current_file_path )
325344 if png_bytes is None :
326345 self .notify (
327346 "Failed to load SVG. The file may be corrupted or not an SVG file." ,
@@ -339,7 +358,16 @@ def show_resvg_preview(self) -> None:
339358
340359 self .call_next (self .LOADER_WIDGET .update , "resampling svg..." )
341360
342- pil_object = preview_utils .resample (Image .open (BytesIO (png_bytes )))
361+ if self .app .MULTIPROCESSING_PROCESS_ALLOWED :
362+ try :
363+ pil_object = preview_utils .resample (Image .open (BytesIO (png_bytes )))
364+ except ValueError as exc :
365+ if multiprocessing_process_error_checker (self .app , exc ):
366+ pil_object = resample_sync (Image .open (BytesIO (png_bytes )))
367+ else :
368+ raise
369+ else :
370+ pil_object = resample_sync (Image .open (BytesIO (png_bytes )))
343371
344372 if should_cancel ():
345373 return
@@ -381,13 +409,26 @@ def show_resvg_preview(self) -> None:
381409 return
382410
383411 def show_image_preview (self ) -> None :
384- """Show image preview. Runs in a thread."""
412+ """Show image preview. Runs in a thread.
413+
414+ Raises:
415+ ValueError: If image loading fails for non-fds_to_keep reasons.
416+ """
385417 if should_cancel () or self ._current_file_path is None :
386418 return
387419 self .app .call_from_thread (setattr , self , "border_title" , titles .image )
388420
389421 try :
390- pil_object = preview_utils .resample_file (self ._current_file_path )
422+ if self .app .MULTIPROCESSING_PROCESS_ALLOWED :
423+ try :
424+ pil_object = preview_utils .resample_file (self ._current_file_path )
425+ except ValueError as exc :
426+ if multiprocessing_process_error_checker (self .app , exc ):
427+ pil_object = resample_file_sync (self ._current_file_path )
428+ else :
429+ raise
430+ else :
431+ pil_object = resample_file_sync (self ._current_file_path )
391432 if pil_object is None :
392433 return
393434 except UnidentifiedImageError :
@@ -480,7 +521,14 @@ def load_pdf_pages(self, first_page: int, last_page: int) -> list[PILImage]:
480521 "Obtained 0 pages from Poppler. Something may have gone wrong..."
481522 )
482523 # Resample images once when loaded for better performance
483- return preview_utils .resample_batch (result )
524+ if self .app .MULTIPROCESSING_PROCESS_ALLOWED :
525+ try :
526+ return preview_utils .resample_batch (result )
527+ except ValueError as exc :
528+ if multiprocessing_process_error_checker (self .app , exc ):
529+ return resample_batch_sync (result )
530+ raise
531+ return resample_batch_sync (result )
484532
485533 def show_pdf_preview (self ) -> None :
486534 """
0 commit comments