Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to accurately estimate the size of an object from python-docx #1431

Open
Soum-Soum opened this issue Sep 12, 2024 · 0 comments
Open

How to accurately estimate the size of an object from python-docx #1431

Soum-Soum opened this issue Sep 12, 2024 · 0 comments

Comments

@Soum-Soum
Copy link

Soum-Soum commented Sep 12, 2024

Hi everyone !

I'd like to accurately estimate the size in ram of objects from the python-docx lib.

I've tried sys.getsizeof() which doesn't work very well. In fact, the object I'm interested in : docx.text.run.Run is just a proxy. So this approach doesn't work.

I also tried pympler.asizeof but I have this rather complicated error to understand :

File "/usr/app/src/annotation/colorization/heuristics/content_awareness.py", line 132, in deep_copy
    print(f"adding {asizeof(obj)} bytes to memory. Object: {obj}")
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 2545, in asizeof
    s = _asizer.asizeof(*t)
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 1954, in asizeof
    return sum(self._sizer(o, 0, 0, None) for o in objs)
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 1954, in <genexpr>
    return sum(self._sizer(o, 0, 0, None) for o in objs)
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 1888, in _sizer
    s += z(o, i, d, None)
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 1888, in _sizer
    s += z(o, i, d, None)
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 1888, in _sizer
    s += z(o, i, d, None)
  [Previous line repeated 13 more times]
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 1887, in _sizer
    for o in v.refs(obj, False):
  File "/usr/local/lib/python3.10/dist-packages/pympler/asizeof.py", line 571, in _refs
    if hasattr(obj, a):
TypeError: descriptor '__dict__' for '_OxmlElementBase' objects doesn't apply to a 'CT_CoreProperties' object

I'm very curious to know if anyone has any ideas for solving this problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant