From 48626c40fdbff62b963eb0a4fd742d4484ad5bce Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sat, 14 Oct 2023 20:10:10 +1100 Subject: [PATCH] fix(backend): handle systems with `glibc` < 2.33 `mallinfo2` is not available on `glibc` < 2.33. On these systems, we successfully load the library but get an `AttributeError` on attempting to access `mallinfo2`. I'm not sure if the old `mallinfo` will work, and not sure how to install it safely to test, so for now we just handle the `AttributeError`. This means the enhanced memory snapshot logic will be skipped for these systems, which isn't a big deal. --- invokeai/backend/model_management/memory_snapshot.py | 6 ++++-- tests/backend/model_management/test_libc_util.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/invokeai/backend/model_management/memory_snapshot.py b/invokeai/backend/model_management/memory_snapshot.py index 4f43affcf7..01f1328114 100644 --- a/invokeai/backend/model_management/memory_snapshot.py +++ b/invokeai/backend/model_management/memory_snapshot.py @@ -55,8 +55,10 @@ class MemorySnapshot: try: malloc_info = LibcUtil().mallinfo2() - except OSError: - # This is expected in environments that do not have the 'libc.so.6' shared library. + except (OSError, AttributeError): + # OSError: This is expected in environments that do not have the 'libc.so.6' shared library. + # AttributeError: This is expected in environments that have `libc.so.6` but do not have the `mallinfo2` (e.g. glibc < 2.33) + # TODO: Does `mallinfo` work? malloc_info = None return cls(process_ram, vram, malloc_info) diff --git a/tests/backend/model_management/test_libc_util.py b/tests/backend/model_management/test_libc_util.py index a517db4c90..e13a2fd3a2 100644 --- a/tests/backend/model_management/test_libc_util.py +++ b/tests/backend/model_management/test_libc_util.py @@ -11,7 +11,10 @@ def test_libc_util_mallinfo2(): # TODO: Set the expected result preemptively based on the system properties. pytest.xfail("libc shared library is not available on this system.") - info = libc.mallinfo2() + try: + info = libc.mallinfo2() + except AttributeError: + pytest.xfail("`mallinfo2` is not available on this system, likely due to glibc < 2.33.") assert info.arena > 0