Skip to content

Commit

Permalink
Merge pull request #344 from Haidra-Org/main
Browse files Browse the repository at this point in the history
fix: ignore numba bytecode dumps; config for ignored messages
  • Loading branch information
tazlin authored Oct 1, 2024
2 parents 7bfb78b + 7a2e468 commit 9f3d457
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions hordelib/comfy_horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,55 @@ class InterceptHandler(logging.Handler):
loguru.
"""

_ignored_message_contents: list[str]
_ignored_libraries: list[str]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._ignored_message_contents = {
"lowvram: loaded module regularly",
"lora key not loaded",
}
self._ignored_libraries = [
"numba.core",
]

def add_ignored_message_content(self, content: str) -> None:
"""Add a message content to ignore."""
self._ignored_message_contents.append(content)

def get_ignored_message_contents(self) -> list[str]:
"""Return the list of ignored message contents."""
return self._ignored_message_contents.copy()

def reset_ignored_message_contents(self) -> None:
"""Reset the list of ignored message contents."""
self._ignored_message_contents = []

def add_ignored_library(self, library: str) -> None:
"""Add a library to ignore."""
self._ignored_libraries.append(library)

def get_ignored_libraries(self) -> list[str]:
"""Return the list of ignored libraries."""
return self._ignored_libraries.copy()

def reset_ignored_libraries(self) -> None:
"""Reset the list of ignored libraries."""
self._ignored_libraries = []

@logger.catch(default=True, reraise=True)
def emit(self, record):
library = record.name
for ignored_library in self._ignored_libraries:
if ignored_library in library:
return

message = record.getMessage()
if "lowvram: loaded module regularly" in message:
return
for ignored_message_content in self._ignored_message_contents:
if ignored_message_content in message:
return

# Get corresponding Loguru level if it exists.
try:
level = logger.level(record.levelname).name
Expand All @@ -141,8 +185,9 @@ def emit(self, record):
logger.opt(depth=depth, exception=record.exc_info).log(level, message)


intercept_handler = InterceptHandler()
# ComfyUI uses stdlib logging, so we need to intercept it.
logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True)
logging.basicConfig(handlers=[intercept_handler], level=0, force=True)


def do_comfy_import(
Expand Down

0 comments on commit 9f3d457

Please sign in to comment.