-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move library load/destory to seprate file
& improve autoclose debug setting
- Loading branch information
Showing
4 changed files
with
26 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2023 geisserml <geisserml@gmail.com> | ||
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause | ||
|
||
import atexit | ||
import logging | ||
import pypdfium2._library_scope | ||
from pypdfium2.version import * | ||
from pypdfium2._helpers import * | ||
from pypdfium2 import raw, internal | ||
|
||
logger = logging.getLogger(__name__) # FIXME perhaps unnecessary? | ||
|
||
# Note: PDFium developers plan changes to the initialisation API (see https://crbug.com/pdfium/1446) | ||
raw.FPDF_InitLibrary() | ||
atexit.register(raw.FPDF_DestroyLibrary) | ||
|
||
del atexit, logging |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SPDX-FileCopyrightText: 2023 geisserml <geisserml@gmail.com> | ||
# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause | ||
|
||
import atexit | ||
import pypdfium2.raw as pdfium_c | ||
import pypdfium2.internal as pdfium_i | ||
|
||
|
||
def destroy_library(): | ||
if pdfium_i.DEBUG_AUTOCLOSE: | ||
import os, sys | ||
os.write(sys.stderr.fileno(), b"Destroy PDFium (auto)\n") | ||
pdfium_c.FPDF_DestroyLibrary() | ||
|
||
# Load pdfium | ||
# Note: PDFium developers plan changes to the initialisation API (see https://crbug.com/pdfium/1446) | ||
pdfium_c.FPDF_InitLibrary() | ||
|
||
# Register an exit handler that will free pdfium | ||
# Trust in Python to call exit handlers only after all objects have been finalized | ||
atexit.register(destroy_library) |
This file contains 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