Comments (5)
I'm afraid we can't do this because the different close functions must be called in correct order, which can't be guaranteed with destructor methods. Using __del__()
is discouraged in general.1 Other libraries like pikepdf or pillow also provide close()
instead.
There might be a weakref
trick which Mike Kroutikov of pdfbrain is currently investigating, but I'm not convinced if this is a good idea for pypdfium2.
Footnotes
from pypdfium2.
See also innodatalabs/pdfbrain#4
__del__
object method is not guaranteed to be called in the refcount order when program exits. This caused random crashes at the exit of programms using pdfbrain.
from pypdfium2.
What @mkroutikov did with weakref doesn't work, I think (see innodatalabs/pdfbrain#6).
However, I believe this should be possible with __del__
anyway. We just need to keep references to parent objects (and their respective parents) and ensure none of them has been closed yet before closing the child object.
However, closing of child objects might then be skipped if parents and children are garbage collected in the same cycle.
I need to verify if closing the parent also frees the memory of the kids - if so, this is not a problem. Otherwise, we might be able to keep track of released child objects via a list of weak references and close them first, even if Python attempts to finalise parent before child...
from pypdfium2.
Actually, I had to revert this again because - despite the order checking - this does still trigger random segfaults on exit, see f59dc65
from pypdfium2.
I think I finally found a working way with weakref, see innodatalabs/pdfbrain#6 (comment).
I've started a branch: autoclose_via_weakref
.
from pypdfium2.
Related Issues (20)
- Library not available: "Cannot close object, library is destroyed..." HOT 4
- conda: consider reading pdfium-binaries version from system?
- Installation failures within a Docker container, problem with ctypesgen? HOT 3
- Parsing special characters leading to inconsistency among different machines HOT 6
- musl binary size concerns
- pdfium fails to load in PHP on Almalinux 8.9 (PartitionAlloc check failure) HOT 8
- Buffer size mismatch when calling `get_text_range` HOT 14
- page.set_rotation() Over Rotating Some Pages
- page.render function returns an unexpected image HOT 7
- PdfDocument.get_page is non-thread-safe HOT 1
- Got different result of "pdfium_page.render()" on MacOS and Linux HOT 1
- Extracting text with special characters HOT 7
- expose more details in PdfiumError HOT 3
- Weird "PDFium: Data format error" when using pypdfium2 in Celery task. HOT 11
- The render func does not render form fields. HOT 4
- pypdfium2 on S390x (ubuntu22.04) HOT 6
- After get_text_bounded, cannot MOVE file HOT 2
- Install with reference bindings broken
- Extract form-filling values from a PDF document that supports Acroform HOT 1
- 当,pdf某一页异常的时候,renderer 到那一页后就会一直卡顿 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pypdfium2.