Skip to content

Commit

Permalink
Redirect gdown.download's stderr to logger.debug
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Dec 30, 2024
1 parent 49de5d6 commit db851bc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion labelme/widgets/canvas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import contextlib

import imgviz
from loguru import logger
from qtpy import QtCore
Expand Down Expand Up @@ -137,7 +139,18 @@ def initializeAiModel(self, name):
logger.debug("AI model is already initialized: %r" % model.name)
else:
logger.debug("Initializing AI model: %r" % model.name)
self._ai_model = model()

class LoggerIO:
def write(self, message: str):
if message := message.strip():
logger.debug(message)

def flush(self):
pass

# NOTE: gdown.download uses sys.stderr, so redirect it to logger.debug
with contextlib.redirect_stderr(new_target=LoggerIO()):
self._ai_model = model()

if self.pixmap is None:
logger.warning("Pixmap is not set yet")
Expand Down

0 comments on commit db851bc

Please sign in to comment.