Enable pikepdf mmap in other contexts

This commit is contained in:
James R. Barlow
2020-07-22 00:20:07 -07:00
parent addc2cbad0
commit a672422b0b
3 changed files with 18 additions and 7 deletions
+8 -6
View File
@@ -64,7 +64,12 @@ from ocrmypdf._validation import (
report_output_file_size,
)
from ocrmypdf.exceptions import ExitCode, ExitCodeException
from ocrmypdf.helpers import available_cpu_count, check_pdf, samefile
from ocrmypdf.helpers import (
available_cpu_count,
check_pdf,
pikepdf_enable_mmap,
samefile,
)
from ocrmypdf.pdfa import file_claims_pdfa
log = logging.getLogger(__name__)
@@ -242,6 +247,7 @@ def worker_init(max_pixels: int):
# the parent process, so ensure workers get it set. Not needed when running
# threaded, but harmless to set again.
PIL.Image.MAX_IMAGE_PIXELS = max_pixels
pikepdf_enable_mmap()
def exec_concurrent(context: PdfContext):
@@ -332,11 +338,7 @@ def run_pipeline(options, *, plugin_manager, api=False):
):
debug_log_handler = configure_debug_logging(Path(work_folder) / "debug.log")
try:
if pikepdf._qpdf.set_access_default_mmap(True):
log.debug("pikepdf mmap enabled")
except AttributeError:
log.debug("pikepdf mmap not available")
pikepdf_enable_mmap()
try:
check_requested_output_file(options)