Skip to content

Commit

Permalink
Merge branch 'tf_disable_interactive_logs'
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Sep 11, 2023
2 parents 9ea6eb9 + 483b9d4 commit a9d330a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
4 changes: 0 additions & 4 deletions ocrd_network/ocrd_network/processing_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@
from .utils import (
calculate_execution_time,
post_to_callback_url,
tf_disable_interactive_logs,
verify_database_uri,
verify_and_parse_mq_uri
)

# TODO: Check this again when the logging is refactored
tf_disable_interactive_logs()


class ProcessingWorker:
def __init__(self, rabbitmq_addr, mongodb_addr, processor_name, ocrd_tool: dict, processor_class=None) -> None:
Expand Down
5 changes: 0 additions & 5 deletions ocrd_network/ocrd_network/processor_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@
calculate_execution_time,
post_to_callback_url,
generate_id,
tf_disable_interactive_logs
)

# TODO: Check this again when the logging is refactored
tf_disable_interactive_logs()


class ProcessorServer(FastAPI):
def __init__(self, mongodb_addr: str, processor_name: str = "", processor_class=None):
if not (processor_name or processor_class):
Expand Down
12 changes: 0 additions & 12 deletions ocrd_network/ocrd_network/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ def calculate_execution_time(start: datetime, end: datetime) -> int:
return int((end - start).total_seconds() * 1000)


def tf_disable_interactive_logs():
try:
# This env variable must be set before importing from Keras
environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from tensorflow.keras.utils import disable_interactive_logging
# Enabled interactive logging throws an exception
# due to a call of sys.stdout.flush()
disable_interactive_logging()
except Exception:
# Nothing should be handled here if TF is not available
pass


def generate_created_time() -> int:
return int(datetime.utcnow().timestamp())
Expand Down
1 change: 1 addition & 0 deletions ocrd_utils/ocrd_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
)

from .logging import (
tf_disable_interactive_logs,
disableLogging,
getLevelName,
getLogger,
Expand Down
14 changes: 14 additions & 0 deletions ocrd_utils/ocrd_utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
'FATAL': 'ERROR',
}

def tf_disable_interactive_logs():
try:
from os import environ
# This env variable must be set before importing from Keras
environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from tensorflow.keras.utils import disable_interactive_logging
# Enabled interactive logging throws an exception
# due to a call of sys.stdout.flush()
disable_interactive_logging()
except ImportError:
# Nothing should be handled here if TF is not available
pass


class PropagationShyLogger(logging.Logger):

def addHandler(self, hdlr):
Expand Down

0 comments on commit a9d330a

Please sign in to comment.